From 7154a9d02413ab81891e26bc3659322bd6c7ee6f Mon Sep 17 00:00:00 2001 From: vend Date: Fri, 11 Nov 2022 14:14:39 +0500 Subject: [PATCH 01/15] upgraded the native form library mvel dependencies --- android-json-form-wizard/build.gradle | 2 +- .../vijay/jsonwizard/activities/JsonFormActivity.java | 9 ++++++++- .../vijay/jsonwizard/filesource/AssetsFileSource.java | 2 +- .../com/vijay/jsonwizard/filesource/DiskFileSource.java | 2 +- .../com/vijay/jsonwizard/rules/RulesEngineFactory.java | 4 ++-- gradle.properties | 2 +- 6 files changed, 14 insertions(+), 7 deletions(-) diff --git a/android-json-form-wizard/build.gradle b/android-json-form-wizard/build.gradle index 26f1516eb..12dc7c508 100644 --- a/android-json-form-wizard/build.gradle +++ b/android-json-form-wizard/build.gradle @@ -109,7 +109,7 @@ dependencies { implementation 'org.smartregister:opensrp-client-utils:0.0.6-SNAPSHOT' implementation 'androidx.test:core:1.4.0' - def easyRulesVersion = '3.4.0' + def easyRulesVersion = '4.1.0' implementation "org.jeasy:easy-rules-core:$easyRulesVersion" implementation "org.jeasy:easy-rules-mvel:$easyRulesVersion" diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/JsonFormActivity.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/JsonFormActivity.java index 42287b5d2..d474f6bf2 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/JsonFormActivity.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/JsonFormActivity.java @@ -85,6 +85,7 @@ import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; +import org.jeasy.rules.annotation.Fact; import org.jeasy.rules.api.Facts; import org.json.JSONArray; import org.json.JSONException; @@ -1427,7 +1428,13 @@ private Facts getEntries(String[] address, JSONObject object) throws JSONExcepti formObject.put(RuleConstant.IS_RULE_CHECK, true); formObject.put(RuleConstant.STEP, formObject.getString(RuleConstant.STEP)); - result.asMap().putAll(getValueFromAddressCore(formObject).asMap()); + + Facts resultFacts = getValueFromAddressCore(formObject); + + for (Map.Entry factEntry: resultFacts.asMap().entrySet()) { + result.put(factEntry.getKey(),factEntry.getValue()); + } + } result.put(RuleConstant.SELECTED_RULE, address[2]); diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java index 6b6da5b20..b6ca39ba2 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java @@ -8,7 +8,7 @@ import org.jeasy.rules.api.Rules; import org.jeasy.rules.mvel.MVELRuleFactory; -import org.jeasy.rules.support.YamlRuleDefinitionReader; +import org.jeasy.rules.support.reader.YamlRuleDefinitionReader; import org.json.JSONObject; import java.io.BufferedReader; diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java index a165a2e53..05d68eb9d 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java @@ -10,7 +10,7 @@ import org.jeasy.rules.api.Rules; import org.jeasy.rules.mvel.MVELRuleFactory; -import org.jeasy.rules.support.YamlRuleDefinitionReader; +import org.jeasy.rules.support.reader.YamlRuleDefinitionReader; import org.json.JSONObject; import java.io.BufferedReader; diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java index 85a840ddb..aa90f1ee4 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java @@ -14,11 +14,11 @@ import org.jeasy.rules.api.RuleListener; import org.jeasy.rules.api.Rules; import org.jeasy.rules.api.RulesEngine; +import org.jeasy.rules.api.RulesEngineParameters; import org.jeasy.rules.core.DefaultRulesEngine; -import org.jeasy.rules.core.RulesEngineParameters; import org.jeasy.rules.mvel.MVELRule; import org.jeasy.rules.mvel.MVELRuleFactory; -import org.jeasy.rules.support.YamlRuleDefinitionReader; +import org.jeasy.rules.support.reader.YamlRuleDefinitionReader; import org.json.JSONArray; import org.json.JSONObject; import org.smartregister.client.utils.contract.ClientFormContract; diff --git a/gradle.properties b/gradle.properties index 5abb92c86..be834e97e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=3.1.1-SNAPSHOT +VERSION_NAME=3.1.2-SNAPSHOT VERSION_CODE=1 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Native Form Json Wizard From cd163c74d178142186d95a7c17d928dc9ed83222 Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Tue, 22 Nov 2022 15:19:15 +0300 Subject: [PATCH 02/15] Fix MVEL rules not working with jeasy-mvel 4.1.0 --- .../activities/JsonFormActivity.java | 5 +++ .../filesource/AssetsFileSource.java | 3 +- .../jsonwizard/filesource/DiskFileSource.java | 3 +- .../jsonwizard/rules/RulesEngineFactory.java | 20 +++++++++--- .../rules/YamlRuleDefinitionReaderExt.java | 32 +++++++++++++++++++ gradle.properties | 2 +- 6 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/YamlRuleDefinitionReaderExt.java diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/JsonFormActivity.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/JsonFormActivity.java index d474f6bf2..47b8ff261 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/JsonFormActivity.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/JsonFormActivity.java @@ -1941,14 +1941,19 @@ private List getRules(String filename, String fieldKey, boolean readAllR conditionString.append(map.get(RuleConstant.CONDITION).toString()); List fields = (List) map.get(RuleConstant.ACTIONS); + List newFields = new ArrayList<>(); if (fields != null) { for (String field : fields) { if (field.trim().startsWith(RuleConstant.CALCULATION) || field.trim().startsWith(RuleConstant.CONSTRAINT)) { conditionString.append(" " + field); } + + newFields.add("facts." + field); } + fields.clear(); + fields.addAll(newFields); } actions.addAll(getConditionKeys(conditionString.toString())); diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java index b6ca39ba2..8372782c8 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java @@ -4,6 +4,7 @@ import com.vijay.jsonwizard.constants.JsonFormConstants; import com.vijay.jsonwizard.interfaces.FormFileSource; +import com.vijay.jsonwizard.rules.YamlRuleDefinitionReaderExt; import com.vijay.jsonwizard.utils.Utils; import org.jeasy.rules.api.Rules; @@ -25,7 +26,7 @@ public class AssetsFileSource implements FormFileSource { private MVELRuleFactory mvelRuleFactory; private AssetsFileSource() { - this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReader()); + this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReaderExt()); } @Override diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java index 05d68eb9d..87b07b485 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java @@ -6,6 +6,7 @@ import com.vijay.jsonwizard.constants.JsonFormConstants; import com.vijay.jsonwizard.interfaces.FormFileSource; +import com.vijay.jsonwizard.rules.YamlRuleDefinitionReaderExt; import com.vijay.jsonwizard.utils.Utils; import org.jeasy.rules.api.Rules; @@ -30,7 +31,7 @@ public class DiskFileSource implements FormFileSource { private MVELRuleFactory mvelRuleFactory; private DiskFileSource() { - this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReader()); + this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReaderExt()); } @Override diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java index aa90f1ee4..ff397affa 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java @@ -52,7 +52,7 @@ public RulesEngineFactory(Context context, Map globalValues) { this.ruleMap = new HashMap<>(); gson = new Gson(); this.rulesEngineHelper = new RulesEngineHelper(); - this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReader()); + this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReaderExt()); if (globalValues != null) { @@ -257,19 +257,31 @@ public void afterEvaluate(Rule rule, Facts facts, boolean evaluationResult) { //Overriden } + @Override public void beforeExecute(Rule rule, Facts facts) { - //Overriden + Timber.e("Putting facts in beforeExecute"); + HashMap myMap = new HashMap<>(); + facts.put("facts", myMap); } @Override public void onSuccess(Rule rule, Facts facts) { - //Overriden + Timber.e("Putting facts in onSuccess"); + HashMap myMap = facts.get("facts"); + + for (String key : + myMap.keySet()) { + facts.put(key, myMap.get(key)); + } + + facts.remove("facts"); } @Override public void onFailure(Rule rule, Facts facts, Exception exception) { - //Overriden + Timber.e("Putting facts in onFailure"); + facts.remove("facts"); } public String getRulesFolderPath() { diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/YamlRuleDefinitionReaderExt.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/YamlRuleDefinitionReaderExt.java new file mode 100644 index 000000000..620c89857 --- /dev/null +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/YamlRuleDefinitionReaderExt.java @@ -0,0 +1,32 @@ +package com.vijay.jsonwizard.rules; + +import org.jeasy.rules.support.RuleDefinition; +import org.jeasy.rules.support.reader.YamlRuleDefinitionReader; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * Created by Ephraim Kigamba - nek.eam@gmail.com on 22-11-2022. + */ +public class YamlRuleDefinitionReaderExt extends YamlRuleDefinitionReader { + + + @Override + protected RuleDefinition createRuleDefinition(Map map) { + RuleDefinition ruleDefinition = super.createRuleDefinition(map); + + List actionList = ruleDefinition.getActions(); + List newActionList = new ArrayList<>(); + + for (int i = 0; i < actionList.size(); i++) { + newActionList.add("facts." + actionList.get(i)); + } + + actionList.clear(); + actionList.addAll(newActionList); + + return ruleDefinition; + } +} diff --git a/gradle.properties b/gradle.properties index be834e97e..c613ca76a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=3.1.2-SNAPSHOT +VERSION_NAME=3.1.5-LOCAL-SNAPSHOT VERSION_CODE=1 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Native Form Json Wizard From 3031f9ea003623176673c2537e3fffc0c2161c91 Mon Sep 17 00:00:00 2001 From: vend Date: Thu, 5 Jan 2023 15:26:33 +0500 Subject: [PATCH 03/15] upgraded the native form library mvel dependencies to local snapshot on which the jackson dependency is updated --- android-json-form-wizard/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android-json-form-wizard/build.gradle b/android-json-form-wizard/build.gradle index 12dc7c508..1c6df8aa5 100644 --- a/android-json-form-wizard/build.gradle +++ b/android-json-form-wizard/build.gradle @@ -109,7 +109,7 @@ dependencies { implementation 'org.smartregister:opensrp-client-utils:0.0.6-SNAPSHOT' implementation 'androidx.test:core:1.4.0' - def easyRulesVersion = '4.1.0' + def easyRulesVersion = '4.1.1-SNAPSHOT' implementation "org.jeasy:easy-rules-core:$easyRulesVersion" implementation "org.jeasy:easy-rules-mvel:$easyRulesVersion" From e9e6b12718bcf55db10669aee8aae35c68c6b942 Mon Sep 17 00:00:00 2001 From: vend Date: Thu, 5 Jan 2023 17:07:41 +0500 Subject: [PATCH 04/15] added backward compatibility option in native forms --- .../src/main/assets/app.properties | 3 +- .../activities/JsonFormActivity.java | 18 +++++---- .../filesource/AssetsFileSource.java | 6 ++- .../jsonwizard/filesource/DiskFileSource.java | 6 ++- .../jsonwizard/rules/RulesEngineFactory.java | 38 ++++++++++++------- .../utils/NativeFormsProperties.java | 1 + 6 files changed, 48 insertions(+), 24 deletions(-) diff --git a/android-json-form-wizard/src/main/assets/app.properties b/android-json-form-wizard/src/main/assets/app.properties index a2e8a9e3a..a2ce92c57 100644 --- a/android-json-form-wizard/src/main/assets/app.properties +++ b/android-json-form-wizard/src/main/assets/app.properties @@ -1,2 +1,3 @@ widget.datepicker.is.numeric=true -widget.value.translated=true \ No newline at end of file +widget.value.translated=true +enable.backward.compatability= true \ No newline at end of file diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/JsonFormActivity.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/JsonFormActivity.java index 47b8ff261..45c57eef1 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/JsonFormActivity.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/JsonFormActivity.java @@ -1428,11 +1428,12 @@ private Facts getEntries(String[] address, JSONObject object) throws JSONExcepti formObject.put(RuleConstant.IS_RULE_CHECK, true); formObject.put(RuleConstant.STEP, formObject.getString(RuleConstant.STEP)); + if(Utils.enabledProperty(NativeFormsProperties.KEY.ENABLE_BACKWARD_COMPATIBILITY)) { + Facts resultFacts = getValueFromAddressCore(formObject); - Facts resultFacts = getValueFromAddressCore(formObject); - - for (Map.Entry factEntry: resultFacts.asMap().entrySet()) { - result.put(factEntry.getKey(),factEntry.getValue()); + for (Map.Entry factEntry : resultFacts.asMap().entrySet()) { + result.put(factEntry.getKey(), factEntry.getValue()); + } } } @@ -1939,6 +1940,7 @@ private List getRules(String filename, String fieldKey, boolean readAllR StringBuilder conditionString = new StringBuilder(); conditionString.append(map.get(RuleConstant.CONDITION).toString()); + boolean backwardCompatibility = Utils.enabledProperty(NativeFormsProperties.KEY.ENABLE_BACKWARD_COMPATIBILITY); List fields = (List) map.get(RuleConstant.ACTIONS); List newFields = new ArrayList<>(); @@ -1948,12 +1950,14 @@ private List getRules(String filename, String fieldKey, boolean readAllR field.trim().startsWith(RuleConstant.CONSTRAINT)) { conditionString.append(" " + field); } - + if(backwardCompatibility) newFields.add("facts." + field); } - fields.clear(); - fields.addAll(newFields); + if(backwardCompatibility) { + fields.clear(); + fields.addAll(newFields); + } } actions.addAll(getConditionKeys(conditionString.toString())); diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java index 8372782c8..a62f48e04 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java @@ -5,6 +5,7 @@ import com.vijay.jsonwizard.constants.JsonFormConstants; import com.vijay.jsonwizard.interfaces.FormFileSource; import com.vijay.jsonwizard.rules.YamlRuleDefinitionReaderExt; +import com.vijay.jsonwizard.utils.NativeFormsProperties; import com.vijay.jsonwizard.utils.Utils; import org.jeasy.rules.api.Rules; @@ -26,7 +27,10 @@ public class AssetsFileSource implements FormFileSource { private MVELRuleFactory mvelRuleFactory; private AssetsFileSource() { - this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReaderExt()); + if(Utils.enabledProperty(NativeFormsProperties.KEY.ENABLE_BACKWARD_COMPATIBILITY)) + this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReaderExt()); + else + this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReader()); } @Override diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java index 87b07b485..613d6484f 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java @@ -7,6 +7,7 @@ import com.vijay.jsonwizard.constants.JsonFormConstants; import com.vijay.jsonwizard.interfaces.FormFileSource; import com.vijay.jsonwizard.rules.YamlRuleDefinitionReaderExt; +import com.vijay.jsonwizard.utils.NativeFormsProperties; import com.vijay.jsonwizard.utils.Utils; import org.jeasy.rules.api.Rules; @@ -31,7 +32,10 @@ public class DiskFileSource implements FormFileSource { private MVELRuleFactory mvelRuleFactory; private DiskFileSource() { - this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReaderExt()); + if(Utils.enabledProperty(NativeFormsProperties.KEY.ENABLE_BACKWARD_COMPATIBILITY)) + this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReaderExt()); + else + this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReader()); } @Override diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java index ff397affa..2c6586b9b 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java @@ -7,6 +7,7 @@ import com.vijay.jsonwizard.activities.JsonFormBaseActivity; import com.vijay.jsonwizard.constants.JsonFormConstants; import com.vijay.jsonwizard.factory.FileSourceFactoryHelper; +import com.vijay.jsonwizard.utils.NativeFormsProperties; import com.vijay.jsonwizard.utils.Utils; import org.jeasy.rules.api.Facts; @@ -43,7 +44,7 @@ public class RulesEngineFactory implements RuleListener { private RulesEngineHelper rulesEngineHelper; private Facts globalFacts; private MVELRuleFactory mvelRuleFactory; - + private boolean backwardCompatibility = Utils.enabledProperty(NativeFormsProperties.KEY.ENABLE_BACKWARD_COMPATIBILITY); public RulesEngineFactory(Context context, Map globalValues) { this.context = context; RulesEngineParameters parameters = new RulesEngineParameters().skipOnFirstAppliedRule(true); @@ -52,7 +53,10 @@ public RulesEngineFactory(Context context, Map globalValues) { this.ruleMap = new HashMap<>(); gson = new Gson(); this.rulesEngineHelper = new RulesEngineHelper(); - this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReaderExt()); + if(backwardCompatibility) + this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReaderExt()); + else + this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReader()); if (globalValues != null) { @@ -260,28 +264,34 @@ public void afterEvaluate(Rule rule, Facts facts, boolean evaluationResult) { @Override public void beforeExecute(Rule rule, Facts facts) { - Timber.e("Putting facts in beforeExecute"); - HashMap myMap = new HashMap<>(); - facts.put("facts", myMap); + if(backwardCompatibility) { + Timber.e("Putting facts in beforeExecute"); + HashMap myMap = new HashMap<>(); + facts.put("facts", myMap); + } } @Override public void onSuccess(Rule rule, Facts facts) { - Timber.e("Putting facts in onSuccess"); - HashMap myMap = facts.get("facts"); + if(backwardCompatibility) { + Timber.e("Putting facts in onSuccess"); + HashMap myMap = facts.get("facts"); - for (String key : - myMap.keySet()) { - facts.put(key, myMap.get(key)); - } + for (String key : + myMap.keySet()) { + facts.put(key, myMap.get(key)); + } - facts.remove("facts"); + facts.remove("facts"); + } } @Override public void onFailure(Rule rule, Facts facts, Exception exception) { - Timber.e("Putting facts in onFailure"); - facts.remove("facts"); + if(backwardCompatibility) { + Timber.e("Putting facts in onFailure"); + facts.remove("facts"); + } } public String getRulesFolderPath() { diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/utils/NativeFormsProperties.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/utils/NativeFormsProperties.java index c31994cba..b7a04782f 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/utils/NativeFormsProperties.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/utils/NativeFormsProperties.java @@ -23,6 +23,7 @@ public final static class KEY { //Widgets public static final String WIDGET_DATEPICKER_IS_NUMERIC = "widget.datepicker.is.numeric"; public static final String WIDGET_VALUE_TRANSLATED = "widget.value.translated"; + public static final String ENABLE_BACKWARD_COMPATIBILITY = "enable.backward.compatability"; } From 4c6314c489c9f7c0c4923802b2cc1c50246e9d8c Mon Sep 17 00:00:00 2001 From: vend Date: Thu, 5 Jan 2023 18:52:59 +0500 Subject: [PATCH 05/15] made adjustments for the compatibility toggle --- android-json-form-wizard/src/main/assets/app.properties | 2 +- .../com/vijay/jsonwizard/filesource/AssetsFileSource.java | 3 --- .../com/vijay/jsonwizard/filesource/DiskFileSource.java | 3 --- .../com/vijay/jsonwizard/rules/RulesEngineFactory.java | 8 +++----- 4 files changed, 4 insertions(+), 12 deletions(-) diff --git a/android-json-form-wizard/src/main/assets/app.properties b/android-json-form-wizard/src/main/assets/app.properties index a2ce92c57..dce771ac6 100644 --- a/android-json-form-wizard/src/main/assets/app.properties +++ b/android-json-form-wizard/src/main/assets/app.properties @@ -1,3 +1,3 @@ widget.datepicker.is.numeric=true widget.value.translated=true -enable.backward.compatability= true \ No newline at end of file +enable.backward.compatability=true \ No newline at end of file diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java index a62f48e04..84ac1a44a 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java @@ -27,10 +27,7 @@ public class AssetsFileSource implements FormFileSource { private MVELRuleFactory mvelRuleFactory; private AssetsFileSource() { - if(Utils.enabledProperty(NativeFormsProperties.KEY.ENABLE_BACKWARD_COMPATIBILITY)) this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReaderExt()); - else - this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReader()); } @Override diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java index 613d6484f..baad25504 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java @@ -32,10 +32,7 @@ public class DiskFileSource implements FormFileSource { private MVELRuleFactory mvelRuleFactory; private DiskFileSource() { - if(Utils.enabledProperty(NativeFormsProperties.KEY.ENABLE_BACKWARD_COMPATIBILITY)) this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReaderExt()); - else - this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReader()); } @Override diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java index 2c6586b9b..6b7db19fb 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java @@ -44,19 +44,17 @@ public class RulesEngineFactory implements RuleListener { private RulesEngineHelper rulesEngineHelper; private Facts globalFacts; private MVELRuleFactory mvelRuleFactory; - private boolean backwardCompatibility = Utils.enabledProperty(NativeFormsProperties.KEY.ENABLE_BACKWARD_COMPATIBILITY); + private boolean backwardCompatibility = false; public RulesEngineFactory(Context context, Map globalValues) { this.context = context; + backwardCompatibility = Utils.enabledProperty(NativeFormsProperties.KEY.ENABLE_BACKWARD_COMPATIBILITY); RulesEngineParameters parameters = new RulesEngineParameters().skipOnFirstAppliedRule(true); this.defaultRulesEngine = new DefaultRulesEngine(parameters); ((DefaultRulesEngine) this.defaultRulesEngine).registerRuleListener(this); this.ruleMap = new HashMap<>(); gson = new Gson(); this.rulesEngineHelper = new RulesEngineHelper(); - if(backwardCompatibility) - this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReaderExt()); - else - this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReader()); + this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReaderExt()); if (globalValues != null) { From 39bddf6abe96b7e46005643a98fb34407a69abcb Mon Sep 17 00:00:00 2001 From: vend Date: Fri, 6 Jan 2023 05:32:22 +0500 Subject: [PATCH 06/15] made adjustments to toggle the backwards compatibility --- .../src/main/assets/app.properties | 2 +- .../jsonwizard/activities/JsonFormActivity.java | 13 ++++++------- .../jsonwizard/filesource/AssetsFileSource.java | 13 +++++++++++++ .../vijay/jsonwizard/filesource/DiskFileSource.java | 10 ++++++++++ .../vijay/jsonwizard/rules/RulesEngineFactory.java | 12 ++++++++++-- .../jsonwizard/utils/NativeFormsProperties.java | 2 +- 6 files changed, 41 insertions(+), 11 deletions(-) diff --git a/android-json-form-wizard/src/main/assets/app.properties b/android-json-form-wizard/src/main/assets/app.properties index dce771ac6..b9ebaae30 100644 --- a/android-json-form-wizard/src/main/assets/app.properties +++ b/android-json-form-wizard/src/main/assets/app.properties @@ -1,3 +1,3 @@ widget.datepicker.is.numeric=true widget.value.translated=true -enable.backward.compatability=true \ No newline at end of file +easy_rule.v3.compatibility=true \ No newline at end of file diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/JsonFormActivity.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/JsonFormActivity.java index 45c57eef1..eba58e260 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/JsonFormActivity.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/JsonFormActivity.java @@ -1,9 +1,5 @@ package com.vijay.jsonwizard.activities; -import static android.view.inputmethod.InputMethodManager.HIDE_NOT_ALWAYS; -import static com.vijay.jsonwizard.utils.FormUtils.getCheckboxValueJsonArray; -import static com.vijay.jsonwizard.utils.FormUtils.getCurrentCheckboxValues; - import android.Manifest; import android.annotation.SuppressLint; import android.app.AlertDialog; @@ -85,7 +81,6 @@ import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; -import org.jeasy.rules.annotation.Fact; import org.jeasy.rules.api.Facts; import org.json.JSONArray; import org.json.JSONException; @@ -109,6 +104,10 @@ import timber.log.Timber; +import static android.view.inputmethod.InputMethodManager.HIDE_NOT_ALWAYS; +import static com.vijay.jsonwizard.utils.FormUtils.getCheckboxValueJsonArray; +import static com.vijay.jsonwizard.utils.FormUtils.getCurrentCheckboxValues; + public class JsonFormActivity extends JsonFormBaseActivity implements JsonApi { private final FormUtils formUtils = new FormUtils(); @@ -1428,7 +1427,7 @@ private Facts getEntries(String[] address, JSONObject object) throws JSONExcepti formObject.put(RuleConstant.IS_RULE_CHECK, true); formObject.put(RuleConstant.STEP, formObject.getString(RuleConstant.STEP)); - if(Utils.enabledProperty(NativeFormsProperties.KEY.ENABLE_BACKWARD_COMPATIBILITY)) { + if (Utils.enabledProperty(NativeFormsProperties.KEY.EASY_RULES_V3_COMPATIBILITY)) { Facts resultFacts = getValueFromAddressCore(formObject); for (Map.Entry factEntry : resultFacts.asMap().entrySet()) { @@ -1940,7 +1939,7 @@ private List getRules(String filename, String fieldKey, boolean readAllR StringBuilder conditionString = new StringBuilder(); conditionString.append(map.get(RuleConstant.CONDITION).toString()); - boolean backwardCompatibility = Utils.enabledProperty(NativeFormsProperties.KEY.ENABLE_BACKWARD_COMPATIBILITY); + boolean backwardCompatibility = Utils.enabledProperty(NativeFormsProperties.KEY.EASY_RULES_V3_COMPATIBILITY); List fields = (List) map.get(RuleConstant.ACTIONS); List newFields = new ArrayList<>(); diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java index 84ac1a44a..a31eedbdd 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java @@ -17,6 +17,8 @@ import java.io.InputStream; import java.io.InputStreamReader; +import timber.log.Timber; + /*** * used to read files stored on the APP's asset folder * @@ -27,7 +29,18 @@ public class AssetsFileSource implements FormFileSource { private MVELRuleFactory mvelRuleFactory; private AssetsFileSource() { + if(Utils.enabledProperty(NativeFormsProperties.KEY.EASY_RULES_V3_COMPATIBILITY)) + { this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReaderExt()); + Timber.e("AssetsFileSource Engaged"); + } + else + { + this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReader()); + Timber.e("AssetsFileSource not Engaged"); + } + + } @Override diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java index baad25504..cd9afc224 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java @@ -22,6 +22,8 @@ import java.io.InputStream; import java.io.InputStreamReader; +import timber.log.Timber; + /** * Returns forms rules and other files stored on the devices * hard disk @@ -32,7 +34,15 @@ public class DiskFileSource implements FormFileSource { private MVELRuleFactory mvelRuleFactory; private DiskFileSource() { + if(Utils.enabledProperty(NativeFormsProperties.KEY.EASY_RULES_V3_COMPATIBILITY)){ this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReaderExt()); + Timber.e("Disk File source Mvel backward compat engaged"); + + } + else { + this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReader()); + Timber.e("Disk File source Mvel backward compat not engaged"); + } } @Override diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java index 6b7db19fb..86c994ab7 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java @@ -47,14 +47,22 @@ public class RulesEngineFactory implements RuleListener { private boolean backwardCompatibility = false; public RulesEngineFactory(Context context, Map globalValues) { this.context = context; - backwardCompatibility = Utils.enabledProperty(NativeFormsProperties.KEY.ENABLE_BACKWARD_COMPATIBILITY); + backwardCompatibility = Utils.getProperties(context).getPropertyBoolean(NativeFormsProperties.KEY.EASY_RULES_V3_COMPATIBILITY); RulesEngineParameters parameters = new RulesEngineParameters().skipOnFirstAppliedRule(true); this.defaultRulesEngine = new DefaultRulesEngine(parameters); ((DefaultRulesEngine) this.defaultRulesEngine).registerRuleListener(this); this.ruleMap = new HashMap<>(); gson = new Gson(); this.rulesEngineHelper = new RulesEngineHelper(); - this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReaderExt()); + if(backwardCompatibility) { + this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReaderExt()); + Timber.e("yaml ext Reader engaged : RulesEngineFactory"); + } + else + { + this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReader()); + Timber.e("yaml ext Reader disengaged : RulesEngineFactory"); + } if (globalValues != null) { diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/utils/NativeFormsProperties.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/utils/NativeFormsProperties.java index b7a04782f..872b01488 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/utils/NativeFormsProperties.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/utils/NativeFormsProperties.java @@ -23,7 +23,7 @@ public final static class KEY { //Widgets public static final String WIDGET_DATEPICKER_IS_NUMERIC = "widget.datepicker.is.numeric"; public static final String WIDGET_VALUE_TRANSLATED = "widget.value.translated"; - public static final String ENABLE_BACKWARD_COMPATIBILITY = "enable.backward.compatability"; + public static final String EASY_RULES_V3_COMPATIBILITY = "easy_rule.v3.compatibility"; } From 463ea9453286f5dbbfba6da3ce929f919c251f76 Mon Sep 17 00:00:00 2001 From: vend Date: Mon, 9 Jan 2023 16:33:29 +0500 Subject: [PATCH 07/15] updated the easy-rules to 4.1.2-snapshot --- android-json-form-wizard/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android-json-form-wizard/build.gradle b/android-json-form-wizard/build.gradle index 1c6df8aa5..bcbe4aa36 100644 --- a/android-json-form-wizard/build.gradle +++ b/android-json-form-wizard/build.gradle @@ -109,7 +109,7 @@ dependencies { implementation 'org.smartregister:opensrp-client-utils:0.0.6-SNAPSHOT' implementation 'androidx.test:core:1.4.0' - def easyRulesVersion = '4.1.1-SNAPSHOT' + def easyRulesVersion = '4.1.2-SNAPSHOT' implementation "org.jeasy:easy-rules-core:$easyRulesVersion" implementation "org.jeasy:easy-rules-mvel:$easyRulesVersion" From 1d9b6f74141f843c3ab716ebaf7f9787e2b682fa Mon Sep 17 00:00:00 2001 From: vend Date: Fri, 24 Feb 2023 13:01:49 +0500 Subject: [PATCH 08/15] updated the easy-rules to 4.1.2-snapshot --- android-json-form-wizard/build.gradle | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/android-json-form-wizard/build.gradle b/android-json-form-wizard/build.gradle index bcbe4aa36..50820c08b 100644 --- a/android-json-form-wizard/build.gradle +++ b/android-json-form-wizard/build.gradle @@ -110,8 +110,13 @@ dependencies { implementation 'androidx.test:core:1.4.0' def easyRulesVersion = '4.1.2-SNAPSHOT' - implementation "org.jeasy:easy-rules-core:$easyRulesVersion" - implementation "org.jeasy:easy-rules-mvel:$easyRulesVersion" + implementation ("org.smartregister:easy-rules-core:$easyRulesVersion"){ + exclude group: 'org.jeasy',module: 'easy-rules-core' + } + implementation ("org.smartregister:easy-rules-mvel:$easyRulesVersion") + { + exclude group: 'org.jeasy', module: 'rules' + } implementation 'joda-time:joda-time:2.10.14' implementation 'com.google.code.gson:gson:2.9.0' From 35df2d306569f54049b795255ca552dcb2f8cb74 Mon Sep 17 00:00:00 2001 From: vend Date: Wed, 1 Mar 2023 17:59:30 +0500 Subject: [PATCH 09/15] gradle fixed --- android-json-form-wizard/build.gradle | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/android-json-form-wizard/build.gradle b/android-json-form-wizard/build.gradle index 50820c08b..223b7447f 100644 --- a/android-json-form-wizard/build.gradle +++ b/android-json-form-wizard/build.gradle @@ -111,11 +111,10 @@ dependencies { def easyRulesVersion = '4.1.2-SNAPSHOT' implementation ("org.smartregister:easy-rules-core:$easyRulesVersion"){ - exclude group: 'org.jeasy',module: 'easy-rules-core' } implementation ("org.smartregister:easy-rules-mvel:$easyRulesVersion") { - exclude group: 'org.jeasy', module: 'rules' + exclude group: 'org.jeasy', module: 'easy-rules-core' } implementation 'joda-time:joda-time:2.10.14' From ffa3354986ce37f92016e8908cabd2abf07870ce Mon Sep 17 00:00:00 2001 From: vend Date: Thu, 2 Mar 2023 03:35:16 +0500 Subject: [PATCH 10/15] added a fix in RulesEngineFactory.java --- .../vijay/jsonwizard/rules/RulesEngineFactory.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java index ff397affa..b99c852ee 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java @@ -1,6 +1,7 @@ package com.vijay.jsonwizard.rules; import android.content.Context; + import androidx.annotation.NonNull; import com.google.gson.Gson; @@ -18,7 +19,6 @@ import org.jeasy.rules.core.DefaultRulesEngine; import org.jeasy.rules.mvel.MVELRule; import org.jeasy.rules.mvel.MVELRuleFactory; -import org.jeasy.rules.support.reader.YamlRuleDefinitionReader; import org.json.JSONArray; import org.json.JSONObject; import org.smartregister.client.utils.contract.ClientFormContract; @@ -64,6 +64,7 @@ public RulesEngineFactory(Context context, Map globalValues) { } public RulesEngineFactory() { + } private Rules getDynamicRulesFromJsonArray(@NonNull JSONArray jsonArray, @NonNull String type) { @@ -99,7 +100,7 @@ private MVELRule getDynamicRulesFromJsonObject(@NonNull JSONObject jsonObjectDyn dynamicMvelRule.setDescription(jsonObjectDynamicRule.optString(RuleConstant.DESCRIPTION)); dynamicMvelRule.setPriority(jsonObjectDynamicRule.optInt(RuleConstant.PRIORITY)); dynamicMvelRule.when(jsonObjectDynamicRule.optString(RuleConstant.CONDITION)); - dynamicMvelRule.then(jsonObjectDynamicRule.optString(RuleConstant.ACTIONS)); + dynamicMvelRule.then("facts." + jsonObjectDynamicRule.optString(RuleConstant.ACTIONS)); dynamicMvelRule.name(jsonObjectDynamicRule.optString(RuleConstant.NAME)); return dynamicMvelRule; } catch (Exception e) { @@ -249,6 +250,14 @@ public String getConstraint(Facts constraintFact, String ruleFilename) { @Override public boolean beforeEvaluate(Rule rule, Facts facts) { + + HashMap myMap = new HashMap<>(); + Map iterationFacts = facts.asMap(); + for (String key : iterationFacts.keySet()) { + myMap.put(key, iterationFacts.get(key)); + } + + facts.put("facts", myMap); return selectedRuleName != null && selectedRuleName.equals(rule.getName()); } From cd25b4c3b19ea081aa3976ce3543f655585723db Mon Sep 17 00:00:00 2001 From: vend Date: Thu, 2 Mar 2023 04:18:16 +0500 Subject: [PATCH 11/15] removed unused imports --- .../java/com/vijay/jsonwizard/activities/JsonFormActivity.java | 1 - .../java/com/vijay/jsonwizard/filesource/AssetsFileSource.java | 1 - .../java/com/vijay/jsonwizard/filesource/DiskFileSource.java | 1 - 3 files changed, 3 deletions(-) diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/JsonFormActivity.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/JsonFormActivity.java index 47b8ff261..9708b7864 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/JsonFormActivity.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/JsonFormActivity.java @@ -85,7 +85,6 @@ import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; -import org.jeasy.rules.annotation.Fact; import org.jeasy.rules.api.Facts; import org.json.JSONArray; import org.json.JSONException; diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java index 8372782c8..a662257fc 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java @@ -9,7 +9,6 @@ import org.jeasy.rules.api.Rules; import org.jeasy.rules.mvel.MVELRuleFactory; -import org.jeasy.rules.support.reader.YamlRuleDefinitionReader; import org.json.JSONObject; import java.io.BufferedReader; diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java index 87b07b485..5908a613c 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java @@ -11,7 +11,6 @@ import org.jeasy.rules.api.Rules; import org.jeasy.rules.mvel.MVELRuleFactory; -import org.jeasy.rules.support.reader.YamlRuleDefinitionReader; import org.json.JSONObject; import java.io.BufferedReader; From f4fb237f8ab1b0154663642c90103c4788dd1188 Mon Sep 17 00:00:00 2001 From: vend Date: Thu, 2 Mar 2023 17:29:17 +0500 Subject: [PATCH 12/15] added necessary imports --- .../java/com/vijay/jsonwizard/filesource/AssetsFileSource.java | 1 + .../java/com/vijay/jsonwizard/filesource/DiskFileSource.java | 1 + .../main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java | 1 + 3 files changed, 3 insertions(+) diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java index be8c27a92..a31eedbdd 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java @@ -10,6 +10,7 @@ import org.jeasy.rules.api.Rules; import org.jeasy.rules.mvel.MVELRuleFactory; +import org.jeasy.rules.support.reader.YamlRuleDefinitionReader; import org.json.JSONObject; import java.io.BufferedReader; diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java index 7912b8a26..cd9afc224 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java @@ -12,6 +12,7 @@ import org.jeasy.rules.api.Rules; import org.jeasy.rules.mvel.MVELRuleFactory; +import org.jeasy.rules.support.reader.YamlRuleDefinitionReader; import org.json.JSONObject; import java.io.BufferedReader; diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java index e0fe0b13c..fba894f0d 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java @@ -20,6 +20,7 @@ import org.jeasy.rules.core.DefaultRulesEngine; import org.jeasy.rules.mvel.MVELRule; import org.jeasy.rules.mvel.MVELRuleFactory; +import org.jeasy.rules.support.reader.YamlRuleDefinitionReader; import org.json.JSONArray; import org.json.JSONObject; import org.smartregister.client.utils.contract.ClientFormContract; From 9ea0a0667f6a54ef831fe4cda8f4727cb9260bcc Mon Sep 17 00:00:00 2001 From: vend Date: Thu, 2 Mar 2023 17:55:11 +0500 Subject: [PATCH 13/15] removed the backwards compatibility check because MVel library is updated it needs the Extended version of YamlRuleDefinitionReader --- .../vijay/jsonwizard/filesource/AssetsFileSource.java | 10 ---------- .../vijay/jsonwizard/filesource/DiskFileSource.java | 10 ---------- .../com/vijay/jsonwizard/rules/RulesEngineFactory.java | 9 +++------ 3 files changed, 3 insertions(+), 26 deletions(-) diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java index a31eedbdd..c4f27997a 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java @@ -29,18 +29,8 @@ public class AssetsFileSource implements FormFileSource { private MVELRuleFactory mvelRuleFactory; private AssetsFileSource() { - if(Utils.enabledProperty(NativeFormsProperties.KEY.EASY_RULES_V3_COMPATIBILITY)) - { this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReaderExt()); Timber.e("AssetsFileSource Engaged"); - } - else - { - this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReader()); - Timber.e("AssetsFileSource not Engaged"); - } - - } @Override diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java index cd9afc224..d2b5e3c7d 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java @@ -7,12 +7,10 @@ import com.vijay.jsonwizard.constants.JsonFormConstants; import com.vijay.jsonwizard.interfaces.FormFileSource; import com.vijay.jsonwizard.rules.YamlRuleDefinitionReaderExt; -import com.vijay.jsonwizard.utils.NativeFormsProperties; import com.vijay.jsonwizard.utils.Utils; import org.jeasy.rules.api.Rules; import org.jeasy.rules.mvel.MVELRuleFactory; -import org.jeasy.rules.support.reader.YamlRuleDefinitionReader; import org.json.JSONObject; import java.io.BufferedReader; @@ -34,15 +32,7 @@ public class DiskFileSource implements FormFileSource { private MVELRuleFactory mvelRuleFactory; private DiskFileSource() { - if(Utils.enabledProperty(NativeFormsProperties.KEY.EASY_RULES_V3_COMPATIBILITY)){ this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReaderExt()); - Timber.e("Disk File source Mvel backward compat engaged"); - - } - else { - this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReader()); - Timber.e("Disk File source Mvel backward compat not engaged"); - } } @Override diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java index fba894f0d..89e5509fb 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java @@ -280,16 +280,14 @@ public void afterEvaluate(Rule rule, Facts facts, boolean evaluationResult) { @Override public void beforeExecute(Rule rule, Facts facts) { - if(backwardCompatibility) { Timber.e("Putting facts in beforeExecute"); HashMap myMap = new HashMap<>(); facts.put("facts", myMap); - } + } @Override public void onSuccess(Rule rule, Facts facts) { - if(backwardCompatibility) { Timber.e("Putting facts in onSuccess"); HashMap myMap = facts.get("facts"); @@ -299,15 +297,14 @@ public void onSuccess(Rule rule, Facts facts) { } facts.remove("facts"); - } } @Override public void onFailure(Rule rule, Facts facts, Exception exception) { - if(backwardCompatibility) { + Timber.e("Putting facts in onFailure"); facts.remove("facts"); - } + } public String getRulesFolderPath() { From 31ca17a77473d0b952dc351a0d411a811ee5bcc8 Mon Sep 17 00:00:00 2001 From: vend Date: Thu, 2 Mar 2023 18:04:10 +0500 Subject: [PATCH 14/15] removed unused imports --- .../jsonwizard/filesource/AssetsFileSource.java | 2 -- .../vijay/jsonwizard/filesource/DiskFileSource.java | 1 - .../vijay/jsonwizard/rules/RulesEngineFactory.java | 12 ++---------- 3 files changed, 2 insertions(+), 13 deletions(-) diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java index c4f27997a..c00a68d32 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java @@ -5,12 +5,10 @@ import com.vijay.jsonwizard.constants.JsonFormConstants; import com.vijay.jsonwizard.interfaces.FormFileSource; import com.vijay.jsonwizard.rules.YamlRuleDefinitionReaderExt; -import com.vijay.jsonwizard.utils.NativeFormsProperties; import com.vijay.jsonwizard.utils.Utils; import org.jeasy.rules.api.Rules; import org.jeasy.rules.mvel.MVELRuleFactory; -import org.jeasy.rules.support.reader.YamlRuleDefinitionReader; import org.json.JSONObject; import java.io.BufferedReader; diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java index d2b5e3c7d..8357d80a9 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java @@ -20,7 +20,6 @@ import java.io.InputStream; import java.io.InputStreamReader; -import timber.log.Timber; /** * Returns forms rules and other files stored on the devices diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java index 89e5509fb..3cdce865e 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java @@ -20,7 +20,6 @@ import org.jeasy.rules.core.DefaultRulesEngine; import org.jeasy.rules.mvel.MVELRule; import org.jeasy.rules.mvel.MVELRuleFactory; -import org.jeasy.rules.support.reader.YamlRuleDefinitionReader; import org.json.JSONArray; import org.json.JSONObject; import org.smartregister.client.utils.contract.ClientFormContract; @@ -55,15 +54,8 @@ public RulesEngineFactory(Context context, Map globalValues) { this.ruleMap = new HashMap<>(); gson = new Gson(); this.rulesEngineHelper = new RulesEngineHelper(); - if(backwardCompatibility) { - this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReaderExt()); - Timber.e("yaml ext Reader engaged : RulesEngineFactory"); - } - else - { - this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReader()); - Timber.e("yaml ext Reader disengaged : RulesEngineFactory"); - } + this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReaderExt()); + Timber.e("yaml ext Reader engaged : RulesEngineFactory"); if (globalValues != null) { From 91c1d386e323c1bec06c63a9ec1df4152127b467 Mon Sep 17 00:00:00 2001 From: vend Date: Fri, 3 Mar 2023 13:39:14 +0500 Subject: [PATCH 15/15] added Backwards Compatibility --- .../filesource/AssetsFileSource.java | 10 +++++++ .../jsonwizard/filesource/DiskFileSource.java | 12 ++++++++ .../jsonwizard/rules/RulesEngineFactory.java | 30 +++++++++++++------ .../rules/RulesEngineFactoryTest.java | 7 +++++ form_tester/src/main/assets/app.properties | 3 +- 5 files changed, 52 insertions(+), 10 deletions(-) diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java index c00a68d32..3d5a6774e 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/AssetsFileSource.java @@ -5,10 +5,12 @@ import com.vijay.jsonwizard.constants.JsonFormConstants; import com.vijay.jsonwizard.interfaces.FormFileSource; import com.vijay.jsonwizard.rules.YamlRuleDefinitionReaderExt; +import com.vijay.jsonwizard.utils.NativeFormsProperties; import com.vijay.jsonwizard.utils.Utils; import org.jeasy.rules.api.Rules; import org.jeasy.rules.mvel.MVELRuleFactory; +import org.jeasy.rules.support.reader.YamlRuleDefinitionReader; import org.json.JSONObject; import java.io.BufferedReader; @@ -27,8 +29,16 @@ public class AssetsFileSource implements FormFileSource { private MVELRuleFactory mvelRuleFactory; private AssetsFileSource() { + if(Utils.enabledProperty(NativeFormsProperties.KEY.EASY_RULES_V3_COMPATIBILITY)) + { this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReaderExt()); Timber.e("AssetsFileSource Engaged"); + } + else + { + this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReader()); + Timber.e("AssetsFileSource not Engaged"); + } } @Override diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java index 8357d80a9..a352eb1bf 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/filesource/DiskFileSource.java @@ -7,10 +7,12 @@ import com.vijay.jsonwizard.constants.JsonFormConstants; import com.vijay.jsonwizard.interfaces.FormFileSource; import com.vijay.jsonwizard.rules.YamlRuleDefinitionReaderExt; +import com.vijay.jsonwizard.utils.NativeFormsProperties; import com.vijay.jsonwizard.utils.Utils; import org.jeasy.rules.api.Rules; import org.jeasy.rules.mvel.MVELRuleFactory; +import org.jeasy.rules.support.reader.YamlRuleDefinitionReader; import org.json.JSONObject; import java.io.BufferedReader; @@ -20,6 +22,8 @@ import java.io.InputStream; import java.io.InputStreamReader; +import timber.log.Timber; + /** * Returns forms rules and other files stored on the devices @@ -31,7 +35,15 @@ public class DiskFileSource implements FormFileSource { private MVELRuleFactory mvelRuleFactory; private DiskFileSource() { + if(Utils.enabledProperty(NativeFormsProperties.KEY.EASY_RULES_V3_COMPATIBILITY)){ this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReaderExt()); + Timber.e("Disk File source Mvel backward compat engaged"); + + } + else { + this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReader()); + Timber.e("Disk File source Mvel backward compat not engaged"); + } } @Override diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java index 3cdce865e..32bb112ab 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java @@ -20,6 +20,7 @@ import org.jeasy.rules.core.DefaultRulesEngine; import org.jeasy.rules.mvel.MVELRule; import org.jeasy.rules.mvel.MVELRuleFactory; +import org.jeasy.rules.support.reader.YamlRuleDefinitionReader; import org.json.JSONArray; import org.json.JSONObject; import org.smartregister.client.utils.contract.ClientFormContract; @@ -54,8 +55,15 @@ public RulesEngineFactory(Context context, Map globalValues) { this.ruleMap = new HashMap<>(); gson = new Gson(); this.rulesEngineHelper = new RulesEngineHelper(); - this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReaderExt()); - Timber.e("yaml ext Reader engaged : RulesEngineFactory"); + if(backwardCompatibility) { + this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReaderExt()); + Timber.e("yaml ext Reader engaged : RulesEngineFactory"); + } + else + { + this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReader()); + Timber.e("yaml ext Reader disengaged : RulesEngineFactory"); + } if (globalValues != null) { @@ -272,23 +280,27 @@ public void afterEvaluate(Rule rule, Facts facts, boolean evaluationResult) { @Override public void beforeExecute(Rule rule, Facts facts) { + if(backwardCompatibility) { Timber.e("Putting facts in beforeExecute"); HashMap myMap = new HashMap<>(); facts.put("facts", myMap); + } } @Override public void onSuccess(Rule rule, Facts facts) { - Timber.e("Putting facts in onSuccess"); - HashMap myMap = facts.get("facts"); + if(backwardCompatibility) { + Timber.e("Putting facts in onSuccess"); + HashMap myMap = facts.get("facts"); - for (String key : - myMap.keySet()) { - facts.put(key, myMap.get(key)); - } + for (String key : + myMap.keySet()) { + facts.put(key, myMap.get(key)); + } - facts.remove("facts"); + facts.remove("facts"); + } } @Override diff --git a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/rules/RulesEngineFactoryTest.java b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/rules/RulesEngineFactoryTest.java index 8032f9306..dee8f9921 100644 --- a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/rules/RulesEngineFactoryTest.java +++ b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/rules/RulesEngineFactoryTest.java @@ -6,6 +6,9 @@ import com.vijay.jsonwizard.activities.JsonFormActivity; import com.vijay.jsonwizard.constants.JsonFormConstants; +import com.vijay.jsonwizard.utils.NativeFormsProperties; +import com.vijay.jsonwizard.utils.Utils; + import org.jeasy.rules.api.Facts; import org.jeasy.rules.api.Rule; import org.jeasy.rules.api.Rules; @@ -43,9 +46,13 @@ public class RulesEngineFactoryTest { @Mock private AssetManager assetManager; + private NativeFormsProperties nativeFormsProperties; + @Before public void setUp() { MockitoAnnotations.initMocks(this); + nativeFormsProperties = Utils.getProperties(context); + nativeFormsProperties.setProperty(NativeFormsProperties.KEY.EASY_RULES_V3_COMPATIBILITY,"true"); rulesEngineFactory = new RulesEngineFactory(); } diff --git a/form_tester/src/main/assets/app.properties b/form_tester/src/main/assets/app.properties index a2e8a9e3a..b9ebaae30 100644 --- a/form_tester/src/main/assets/app.properties +++ b/form_tester/src/main/assets/app.properties @@ -1,2 +1,3 @@ widget.datepicker.is.numeric=true -widget.value.translated=true \ No newline at end of file +widget.value.translated=true +easy_rule.v3.compatibility=true \ No newline at end of file