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,82 +124,84 @@ 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)
{
includeInherited = includeInheritedValue.booleanValue();
}
boolean runAllChildren = false; // Get the parameter value
Boolean runAllChildrenValue = (Boolean)ruleAction.getParameterValue(PARAM_RUN_ALL_RULES_ON_CHILDREN); boolean includeInherited = false;
if (runAllChildrenValue != null) Boolean includeInheritedValue = (Boolean)ruleAction.getParameterValue(PARAM_EXECUTE_INHERITED_RULES);
{ if (includeInheritedValue != null)
runAllChildren = runAllChildrenValue.booleanValue(); {
} includeInherited = includeInheritedValue.booleanValue();
}
// Collect all the rules to execute on the current node. boolean runAllChildren = false;
List<Rule> rules = new ArrayList<>(); Boolean runAllChildrenValue = (Boolean)ruleAction.getParameterValue(PARAM_RUN_ALL_RULES_ON_CHILDREN);
// This is a recursive method, collect the rules specified for this particular invocation's node. if (runAllChildrenValue != null)
List<Rule> currentNodeRules = ruleService.getRules(actionedUponNodeRef, includeInherited); {
if (currentNodeRules != null) runAllChildren = runAllChildrenValue.booleanValue();
{ }
rules.addAll(currentNodeRules);
}
if (runAllChildren) // Collect all the rules to execute on the current node.
List<Rule> rules = new ArrayList<>();
// This is a recursive method, collect the rules specified for this particular invocation's node.
List<Rule> currentNodeRules = ruleService.getRules(actionedUponNodeRef, includeInherited);
if (currentNodeRules != null)
{
rules.addAll(currentNodeRules);
}
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.
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;
}
}
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)
{ {
// Currently recursing into a child folder, add the rules from the recursive set for (Rule rule : rules)
// 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;
}
}
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)
{ {
for (Rule rule : rules) // Only re-apply rules that are enabled
{ if (rule.getRuleDisabled() == false)
// Only re-apply rules that are enabled {
if (rule.getRuleDisabled() == false) Action action = rule.getAction();
if (action != null)
{ {
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 the child is a folder and we have asked to run rules on children
if (runAllChildren == true && if (runAllChildren == true &&
dictionaryService.isSubClass(childType, ContentModel.TYPE_FOLDER) == true) dictionaryService.isSubClass(childType, ContentModel.TYPE_FOLDER) == true)
{ {
// Recurse with the child folder, passing down the top-level folder rules. // Recurse with the child folder, passing down the top-level folder rules.
executeImpl(ruleAction, child, parentRules); executeImpl(ruleAction, child, parentRules);
}
} }
} }
} }