sergehuber commented on a change in pull request #365:
URL: https://github.com/apache/unomi/pull/365#discussion_r753000900
##########
File path:
services/src/main/java/org/apache/unomi/services/impl/rules/RulesServiceImpl.java
##########
@@ -393,6 +408,11 @@ public void setRule(Rule rule) {
definitionsService.extractConditionBySystemTag(condition,
"eventCondition");
}
}
+ List<Action> actions = rule.getActions();
+ if (actions == null || actions.isEmpty()) {
+ logger.warn("rule {} won't be saved as it contains no action",
rule.getItemId());
+ return;
+ }
Review comment:
I think I would be more in favor of raising an exception in this case.
##########
File path:
services/src/main/java/org/apache/unomi/services/impl/rules/RulesServiceImpl.java
##########
@@ -277,11 +277,26 @@ public void refreshRules() {
private List<Rule> getAllRules() {
List<Rule> rules = persistenceService.getAllItems(Rule.class, 0, -1,
"priority").getList();
+ List<Rule> rulesToDisable = new ArrayList<>();
+ List<Rule> enabledRules = new ArrayList<>();
for (Rule rule : rules) {
- ParserHelper.resolveConditionType(definitionsService,
rule.getCondition(), "rule " + rule.getItemId());
- ParserHelper.resolveActionTypes(definitionsService, rule);
+ // Check rule integrity
+ boolean isValid =
ParserHelper.resolveConditionType(definitionsService, rule.getCondition(),
"rule " + rule.getItemId());
+ isValid = isValid &&
ParserHelper.resolveActionTypes(definitionsService, rule);
+ // exclude enabled invalid rules
+ if (isValid) {
+ enabledRules.add(rule);
+ } else if (rule.getMetadata().isEnabled()) {
+ rulesToDisable.add(rule);
+ }
}
- return rules;
+ // Disable invalid rules and store it.
+ rulesToDisable.forEach(rule -> {
Review comment:
I wonder if we should put a setting around this ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]