Skip to content

Commit

Permalink
made adjustments to toggle the backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
junaidwarsivd committed Jan 6, 2023
1 parent 4c6314c commit 39bddf6
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 11 deletions.
2 changes: 1 addition & 1 deletion android-json-form-wizard/src/main/assets/app.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
widget.datepicker.is.numeric=true
widget.value.translated=true
enable.backward.compatability=true
easy_rule.v3.compatibility=true
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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<String, Object> factEntry : resultFacts.asMap().entrySet()) {
Expand Down Expand Up @@ -1940,7 +1939,7 @@ private List<String> 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<String> fields = (List<String>) map.get(RuleConstant.ACTIONS);
List<String> newFields = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,22 @@ public class RulesEngineFactory implements RuleListener {
private boolean backwardCompatibility = false;
public RulesEngineFactory(Context context, Map<String, String> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";


}
Expand Down

0 comments on commit 39bddf6

Please sign in to comment.