-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add expert filter feature #71
Conversation
src/main/java/org/gridsuite/filter/server/ExpertFilterRepositoryProxy.java
Outdated
Show resolved
Hide resolved
src/main/java/org/gridsuite/filter/server/ExpertFilterRepositoryProxy.java
Outdated
Show resolved
Hide resolved
src/main/java/org/gridsuite/filter/server/dto/ExpertFilter.java
Outdated
Show resolved
Hide resolved
src/main/java/org/gridsuite/filter/server/dto/expertrule/AbstractExpertRule.java
Outdated
Show resolved
Hide resolved
src/main/java/org/gridsuite/filter/server/dto/expertrule/BooleanExpertRule.java
Outdated
Show resolved
Hide resolved
src/main/java/org/gridsuite/filter/server/utils/OperatorType.java
Outdated
Show resolved
Hide resolved
src/main/java/org/gridsuite/filter/server/utils/ExpertFilterUtils.java
Outdated
Show resolved
Hide resolved
src/main/java/org/gridsuite/filter/server/utils/ExpertFilterUtils.java
Outdated
Show resolved
Hide resolved
Improve test coverage.
|
||
@Override | ||
public boolean evaluateRule(String identifiableValue) { | ||
return false; |
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.
Should implement this method as other single rule? Take the implementation found in ExpertFilterUtils
` public static <I extends Injection> boolean evaluateExpertFilter(AbstractExpertRule filter, Injection injection) {
// As long as there are rules, we go down the tree
if (CombinatorType.AND == (filter.getCombinator())) {
return evaluateAndCombination(filter, injection);
} else if (CombinatorType.OR == filter.getCombinator()) {
return evaluateOrCombination(filter, injection);
} else {
// Evaluate individual filters
return filter.evaluateRule(getFieldValue(filter.getField(), injection));
}
}
private static <I extends Injection<I>> boolean evaluateOrCombination(AbstractExpertRule filter, Injection<I> injection) {
for (AbstractExpertRule rule : filter.getRules()) {
// Recursively evaluate the rule
if (evaluateExpertFilter(rule, injection)) {
// If any rule is true, the whole combination is true
return true;
}
}
return false;
}`
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.
It's not possible with this model to implement what you suggest. Combinator rules are a special type of rules and should be handled separately. The AbstractExpertRule.evaluateRule()
function is meant to evaluate a rule with respect to a value not to a combinator. This applies only to boolean, enum, string or number rules. See for example the signature of evaluateRule()
compared with public static <I extends Injection> boolean evaluateExpertFilter(AbstractExpertRule filter, Injection injection)
that you suggest moving to CombinatorRule.evaluateRule()
.
We could implement in CombinatorRule.evaluateRule(String combinatorValue)
something like getCombinator().toString().equals(combinatorValue)
but I don't think it should be used this way as it's a particular type of rule.
src/main/java/org/gridsuite/filter/server/entities/ExpertFilterEntity.java
Outdated
Show resolved
Hide resolved
src/main/java/org/gridsuite/filter/server/entities/ExpertFilterEntity.java
Outdated
Show resolved
Hide resolved
src/main/java/org/gridsuite/filter/server/entities/ExpertRuleEntity.java
Outdated
Show resolved
Hide resolved
src/main/java/org/gridsuite/filter/server/entities/ExpertRuleEntity.java
Outdated
Show resolved
Hide resolved
public static <I extends Injection<I>> boolean evaluateExpertFilter(AbstractExpertRule filter, Injection<I> injection) { | ||
// As long as there are rules, we go down the tree | ||
if (CombinatorType.AND == (filter.getCombinator())) { | ||
return evaluateAndCombination(filter, injection); | ||
} else if (CombinatorType.OR == filter.getCombinator()) { | ||
return evaluateOrCombination(filter, injection); | ||
} else { | ||
// Evaluate individual filters | ||
return filter.evaluateRule(getFieldValue(filter.getField(), injection)); | ||
} | ||
} | ||
|
||
private static <I extends Injection<I>> boolean evaluateOrCombination(AbstractExpertRule filter, Injection<I> injection) { | ||
for (AbstractExpertRule rule : filter.getRules()) { | ||
// Recursively evaluate the rule | ||
if (evaluateExpertFilter(rule, injection)) { | ||
// If any rule is true, the whole combination is true | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
private static <I extends Injection<I>> boolean evaluateAndCombination(AbstractExpertRule filter, Injection<I> injection) { | ||
for (AbstractExpertRule rule : filter.getRules()) { | ||
// Recursively evaluate the rule | ||
if (!evaluateExpertFilter(rule, injection)) { | ||
// If any rule is false, the whole combination is false | ||
return false; | ||
} | ||
} | ||
return true; | ||
} |
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.
move to the implementation of CombinatorExpertRule#evaluateRule
src/main/java/org/gridsuite/filter/server/ExpertFilterRepositoryProxy.java
Outdated
Show resolved
Hide resolved
src/main/java/org/gridsuite/filter/server/ExpertFilterRepositoryProxy.java
Outdated
Show resolved
Hide resolved
src/main/java/org/gridsuite/filter/server/ExpertFilterRepositoryProxy.java
Outdated
Show resolved
Hide resolved
src/main/java/org/gridsuite/filter/server/ExpertFilterRepositoryProxy.java
Outdated
Show resolved
Hide resolved
src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java
Outdated
Show resolved
Hide resolved
I created #75 for the reorganization of files by filter type. |
Signed-off-by: BOUHOURS Antoine <[email protected]>
Signed-off-by: BOUHOURS Antoine <[email protected]>
Signed-off-by: BOUHOURS Antoine <[email protected]>
Signed-off-by: BOUHOURS Antoine <[email protected]>
Kudos, SonarCloud Quality Gate passed! |
No description provided.