-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vunerability upgrade PR #917
Open
junaidwarsivd
wants to merge
11
commits into
master
Choose a base branch
from
vunerability-upgrades
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
05b6b99
did vunerability upgrade
junaidwarsivd 53d84fe
Merge branch 'master' into vunerability-upgrades
dubdabasoduba 8a918da
Merge branch 'master' into vunerability-upgrades
dubdabasoduba 2487a63
jeasy rules updated
junaidwarsivd f137da7
Merge branch 'vunerability-upgrades' of https://github.com/opensrp/op…
junaidwarsivd 787a4ae
Fix MVEL rules not working with jeasy-mvel 4.1.0
ekigamba bf1c172
uptadated the facts population in rulesEnginehelper
junaidwarsivd 1ed864a
fixed the AncRulesEngineFactory and AncRulesEngineHelper for the not …
junaidwarsivd 5c0a8c7
fixed the AncRulesEngineFactory and AncRulesEngineHelper for the not …
junaidwarsivd 0e3bc05
updated the vunerability changes
junaidwarsivd 4518bad
removed dependencies that were already included in native forms
junaidwarsivd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
opensrp-anc/src/main/java/org/smartregister/anc/library/YamlRuleDefinitionReaderExt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.smartregister.anc.library; | ||
|
||
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 - [email protected] on 22-11-2022. | ||
*/ | ||
public class YamlRuleDefinitionReaderExt extends YamlRuleDefinitionReader { | ||
|
||
|
||
@Override | ||
protected RuleDefinition createRuleDefinition(Map<String, Object> map) { | ||
RuleDefinition ruleDefinition = super.createRuleDefinition(map); | ||
|
||
List<String> actionList = ruleDefinition.getActions(); | ||
List<String> newActionList = new ArrayList<>(); | ||
|
||
for (int i = 0; i < actionList.size(); i++) { | ||
newActionList.add("facts." + actionList.get(i)); | ||
} | ||
|
||
actionList.clear(); | ||
actionList.addAll(newActionList); | ||
|
||
return ruleDefinition; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,15 @@ | |
|
||
import org.jeasy.rules.api.Facts; | ||
import org.jeasy.rules.api.Rule; | ||
import org.jeasy.rules.mvel.MVELAction; | ||
import org.jeasy.rules.mvel.MVELRule; | ||
import org.json.JSONObject; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import timber.log.Timber; | ||
|
||
public class AncRulesEngineFactory extends RulesEngineFactory { | ||
private Map<String, String> globalValues; | ||
private AncRulesEngineHelper ancRulesEngineHelper; | ||
|
@@ -22,7 +27,6 @@ public AncRulesEngineFactory(Context context, Map<String, String> globalValues, | |
this.ancRulesEngineHelper = new AncRulesEngineHelper(context); | ||
this.ancRulesEngineHelper.setJsonObject(mJSONObject); | ||
this.globalValues = globalValues; | ||
|
||
} | ||
|
||
@Override | ||
|
@@ -45,4 +49,36 @@ protected Facts initializeFacts(Facts facts) { | |
public boolean beforeEvaluate(Rule rule, Facts facts) { | ||
return selectedRuleName != null && selectedRuleName.equals(rule.getName()); | ||
} | ||
|
||
@Override | ||
public void beforeExecute(Rule rule, Facts facts) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can possibly remove this and use what is on native form |
||
super.beforeExecute(rule, facts); | ||
|
||
Timber.e("Putting facts in beforeExecute"); | ||
HashMap<String, Object> myMap = new HashMap<>(); | ||
facts.put("facts", myMap); | ||
} | ||
|
||
@Override | ||
public void onSuccess(Rule rule, Facts facts) { | ||
super.onSuccess(rule, facts); | ||
|
||
Timber.e("Putting facts in onSuccess"); | ||
HashMap<String, Object> 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) { | ||
super.onFailure(rule, facts, exception); | ||
|
||
Timber.e("Putting facts in onFailure"); | ||
facts.remove("facts"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,18 +10,22 @@ | |
|
||
import org.jeasy.rules.api.Facts; | ||
import org.jeasy.rules.api.Rule; | ||
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.InferenceRulesEngine; | ||
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.joda.time.LocalDate; | ||
import org.json.JSONArray; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
import org.smartregister.anc.library.YamlRuleDefinitionReaderExt; | ||
import org.smartregister.anc.library.rule.AlertRule; | ||
import org.smartregister.anc.library.rule.ContactRule; | ||
import org.smartregister.anc.library.util.ANCFormUtils; | ||
|
@@ -51,14 +55,33 @@ public class AncRulesEngineHelper extends RulesEngineHelper { | |
private final RulesEngine defaultRulesEngine; | ||
private final Map<String, Rules> ruleMap; | ||
private JSONObject mJsonObject = new JSONObject(); | ||
private final YamlRuleDefinitionReader yamlRuleDefinitionReader = new YamlRuleDefinitionReader(); | ||
private final YamlRuleDefinitionReaderExt yamlRuleDefinitionReader = new YamlRuleDefinitionReaderExt(); | ||
private final MVELRuleFactory mvelRuleFactory = new MVELRuleFactory(yamlRuleDefinitionReader); | ||
|
||
public AncRulesEngineHelper(Context context) { | ||
this.context = context; | ||
this.inferentialRulesEngine = new InferenceRulesEngine(); | ||
RulesEngineParameters parameters = new RulesEngineParameters().skipOnFirstAppliedRule(true); | ||
this.defaultRulesEngine = new DefaultRulesEngine(parameters); | ||
/* ((DefaultRulesEngine) this.defaultRulesEngine).registerRuleListener(new RuleListener() { | ||
@Override | ||
public void beforeExecute(Rule rule, Facts facts) { | ||
Timber.e("Putting facts in beforeExecute"); | ||
facts.put("facts", facts); | ||
} | ||
|
||
@Override | ||
public void onSuccess(Rule rule, Facts facts) { | ||
Timber.e("Putting facts in onSuccess"); | ||
facts.remove("facts"); | ||
} | ||
|
||
@Override | ||
public void onFailure(Rule rule, Facts facts, Exception exception) { | ||
Timber.e("Putting facts in onFailure"); | ||
facts.remove("facts"); | ||
} | ||
});*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can discard these changes |
||
this.ruleMap = new HashMap<>(); | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be removed and we can use the one on native form