diff --git a/android-json-form-wizard/src/main/assets/app.properties b/android-json-form-wizard/src/main/assets/app.properties index a2e8a9e3a..b9ebaae30 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 +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 47b8ff261..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,11 +1427,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.EASY_RULES_V3_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 +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.EASY_RULES_V3_COMPATIBILITY); List fields = (List) map.get(RuleConstant.ACTIONS); List newFields = new ArrayList<>(); @@ -1948,12 +1949,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..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 @@ -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; @@ -16,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 * @@ -26,7 +29,18 @@ public class AssetsFileSource implements FormFileSource { private MVELRuleFactory mvelRuleFactory; private AssetsFileSource() { - this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReaderExt()); + 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 87b07b485..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 @@ -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; @@ -21,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 @@ -31,7 +34,15 @@ public class DiskFileSource implements FormFileSource { private MVELRuleFactory mvelRuleFactory; private DiskFileSource() { - this.mvelRuleFactory = new MVELRuleFactory(new YamlRuleDefinitionReaderExt()); + 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 ff397affa..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 @@ -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,16 +44,25 @@ public class RulesEngineFactory implements RuleListener { private RulesEngineHelper rulesEngineHelper; private Facts globalFacts; private MVELRuleFactory mvelRuleFactory; - + private boolean backwardCompatibility = false; public RulesEngineFactory(Context context, Map globalValues) { this.context = context; + 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) { @@ -260,28 +270,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..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,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 EASY_RULES_V3_COMPATIBILITY = "easy_rule.v3.compatibility"; }