REPO-3029/MNT-13055: code cleanup - refactor if statement

Entire method body was in an if statement. This is a small change
to return early with inverted logic condition.
This commit is contained in:
Matt Ward
2017-11-09 13:42:11 +00:00
parent af0460e63a
commit b2205af9c1

View File

@@ -124,84 +124,86 @@ public class ExecuteAllRulesActionExecuter extends ActionExecuterAbstractBase
private void executeImpl(final Action ruleAction, NodeRef actionedUponNodeRef, List<Rule> parentRules) private void executeImpl(final Action ruleAction, NodeRef actionedUponNodeRef, List<Rule> parentRules)
{ {
if (this.nodeService.exists(actionedUponNodeRef) == true) if (!this.nodeService.exists(actionedUponNodeRef))
{ {
// Get the parameter value return;
boolean includeInherited = false; }
Boolean includeInheritedValue = (Boolean)ruleAction.getParameterValue(PARAM_EXECUTE_INHERITED_RULES);
if (includeInheritedValue != null) // Get the parameter value
{ boolean includeInherited = false;
includeInherited = includeInheritedValue.booleanValue(); Boolean includeInheritedValue = (Boolean)ruleAction.getParameterValue(PARAM_EXECUTE_INHERITED_RULES);
} if (includeInheritedValue != null)
{
boolean runAllChildren = false; includeInherited = includeInheritedValue.booleanValue();
Boolean runAllChildrenValue = (Boolean)ruleAction.getParameterValue(PARAM_RUN_ALL_RULES_ON_CHILDREN); }
if (runAllChildrenValue != null)
{ boolean runAllChildren = false;
runAllChildren = runAllChildrenValue.booleanValue(); Boolean runAllChildrenValue = (Boolean)ruleAction.getParameterValue(PARAM_RUN_ALL_RULES_ON_CHILDREN);
} if (runAllChildrenValue != null)
{
runAllChildren = runAllChildrenValue.booleanValue();
}
// Collect all the rules to execute on the current node. // Collect all the rules to execute on the current node.
List<Rule> rules = new ArrayList<>(); List<Rule> rules = new ArrayList<>();
// This is a recursive method, collect the rules specified for this particular invocation's node. // This is a recursive method, collect the rules specified for this particular invocation's node.
List<Rule> currentNodeRules = ruleService.getRules(actionedUponNodeRef, includeInherited); List<Rule> currentNodeRules = ruleService.getRules(actionedUponNodeRef, includeInherited);
if (currentNodeRules != null) if (currentNodeRules != null)
{ {
rules.addAll(currentNodeRules); rules.addAll(currentNodeRules);
} }
if (runAllChildren) if (runAllChildren)
{
if (parentRules != null)
{ {
if (parentRules != null) // Currently recursing into a child folder, add the rules from the recursive set
{ // to any other rules we've collected for this node.
// Currently recursing into a child folder, add the rules from the recursive set rules.addAll(parentRules);
// to any other rules we've collected for this node.
rules.addAll(parentRules);
}
else
{
// Currently executing on the "top-level" folder.
// We'll propagate the rules of the top-level node during recursive calls,
// so save the rules (parentRules) to pass down the line.
parentRules = currentNodeRules;
}
} }
else
if (!rules.isEmpty())
{ {
// Get the child nodes for the actioned upon node // Currently executing on the "top-level" folder.
List<ChildAssociationRef> children = nodeService.getChildAssocs(actionedUponNodeRef); // We'll propagate the rules of the top-level node during recursive calls,
for (ChildAssociationRef childAssoc : children) // so save the rules (parentRules) to pass down the line.
parentRules = currentNodeRules;
}
}
if (!rules.isEmpty())
{
// Get the child nodes for the actioned upon node
List<ChildAssociationRef> children = nodeService.getChildAssocs(actionedUponNodeRef);
for (ChildAssociationRef childAssoc : children)
{
// Get the child node reference
NodeRef child = childAssoc.getChildRef();
// Only execute rules on non-system folders
QName childType = nodeService.getType(child);
if (dictionaryService.isSubClass(childType, ContentModel.TYPE_SYSTEM_FOLDER) == false)
{ {
// Get the child node reference for (Rule rule : rules)
NodeRef child = childAssoc.getChildRef(); {
// Only re-apply rules that are enabled
// Only execute rules on non-system folders if (rule.getRuleDisabled() == false)
QName childType = nodeService.getType(child); {
if (dictionaryService.isSubClass(childType, ContentModel.TYPE_SYSTEM_FOLDER) == false) Action action = rule.getAction();
{ if (action != null)
for (Rule rule : rules)
{
// Only re-apply rules that are enabled
if (rule.getRuleDisabled() == false)
{ {
Action action = rule.getAction(); runtimeRuleService.addRulePendingExecution(actionedUponNodeRef, child, rule);
if (action != null)
{
runtimeRuleService.addRulePendingExecution(actionedUponNodeRef, child, rule);
}
} }
} }
}
// If the child is a folder and we have asked to run rules on children
if (runAllChildren == true && // If the child is a folder and we have asked to run rules on children
dictionaryService.isSubClass(childType, ContentModel.TYPE_FOLDER) == true) if (runAllChildren == true &&
{ dictionaryService.isSubClass(childType, ContentModel.TYPE_FOLDER) == true)
// Recurse with the child folder, passing down the top-level folder rules. {
executeImpl(ruleAction, child, parentRules); // Recurse with the child folder, passing down the top-level folder rules.
} executeImpl(ruleAction, child, parentRules);
} }
} }
} }
} }
} }