From 44a188dabf45d091292ef1f0bf23f2c19f9e34cc Mon Sep 17 00:00:00 2001 From: Roy Wetherall Date: Tue, 15 Mar 2016 11:59:13 +1100 Subject: [PATCH] Remove now unessesary checks from rule execution (RM-3148) --- .../repo/rule/ExtendedRuleServiceImpl.java | 100 +++++------------- .../rule/FilePlanRuleInheritanceTest.java | 6 +- 2 files changed, 32 insertions(+), 74 deletions(-) diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/repo/rule/ExtendedRuleServiceImpl.java b/rm-community/rm-community-repo/source/java/org/alfresco/repo/rule/ExtendedRuleServiceImpl.java index e6c0ed2f8e..7965967d8d 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/repo/rule/ExtendedRuleServiceImpl.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/repo/rule/ExtendedRuleServiceImpl.java @@ -171,39 +171,37 @@ public class ExtendedRuleServiceImpl extends RuleServiceImpl if (nodeService.exists(nodeRef)) { QName typeQName = nodeService.getType(nodeRef); - if (shouldRuleBeAppliedToNode(rule, nodeRef, typeQName)) + + // check if this is a rm rule on a rm artifact + if (filePlanService.isFilePlanComponent(nodeRef) && + isFilePlanComponentRule(rule)) { - // check if this is a rm rule on a rm artifact - if (filePlanService.isFilePlanComponent(nodeRef) && - isFilePlanComponentRule(rule)) - { - // ignore and - if (!isIgnoredType(typeQName)) - { - if (runAsAdmin) - { - AuthenticationUtil.runAs(new RunAsWork() + // ignore and + if (!isIgnoredType(typeQName)) + { + if (runAsAdmin) + { + AuthenticationUtil.runAs(new RunAsWork() + { + @Override + public Void doWork() { - @Override - public Void doWork() - { - ExtendedRuleServiceImpl.super.executeRule(rule, nodeRef, executedRules); - return null; - } - }, AuthenticationUtil.getAdminUserName()); - } - else - { - // run as current user - super.executeRule(rule, nodeRef, executedRules); - } - } - } - else - { - // just execute the rule as the current user - super.executeRule(rule, nodeRef, executedRules); - } + ExtendedRuleServiceImpl.super.executeRule(rule, nodeRef, executedRules); + return null; + } + }, AuthenticationUtil.getAdminUserName()); + } + else + { + // run as current user + super.executeRule(rule, nodeRef, executedRules); + } + } + } + else + { + // just execute the rule as the current user + super.executeRule(rule, nodeRef, executedRules); } } } @@ -228,44 +226,4 @@ public class ExtendedRuleServiceImpl extends RuleServiceImpl { return ignoredTypes.contains(typeQName); } - - /** - * Check if the rule is associated with the file plan component that the node it is being - * applied to isn't a hold container, a hold, a transfer container, a transfer, an unfiled - * record container, an unfiled record folder or unfiled content - * - * @param rule - * @param nodeRef - * @param typeQName - * @return - */ - private boolean shouldRuleBeAppliedToNode(final Rule rule, final NodeRef nodeRef, final QName typeQName) - { - return AuthenticationUtil.runAsSystem(new RunAsWork() - { - public Boolean doWork() throws Exception - { - boolean result = true; - NodeRef ruleNodeRef = getOwningNodeRef(rule); - if (filePlanService.isFilePlan(ruleNodeRef)) - { - // if this rule is defined at the root of the file plan then - // we do not want to apply - // it to holds/transfers/unfiled content... - result = !(RecordsManagementModel.TYPE_HOLD.equals(typeQName) - || RecordsManagementModel.TYPE_HOLD_CONTAINER.equals(typeQName) - || RecordsManagementModel.TYPE_TRANSFER.equals(typeQName) - || RecordsManagementModel.TYPE_TRANSFER_CONTAINER.equals(typeQName) - || RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER - .equals(typeQName) - || RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER.equals(typeQName) - || nodeService.hasAspect(nodeRef, - RecordsManagementModel.ASPECT_TRANSFERRING) - || nodeService.hasAspect(nodeRef, RecordsManagementModel.ASPECT_FROZEN) - || !recordService.isFiled(nodeRef)); - } - return result; - } - }); - } } diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/rule/FilePlanRuleInheritanceTest.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/rule/FilePlanRuleInheritanceTest.java index ab97dc4ecd..e4cecd7033 100644 --- a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/rule/FilePlanRuleInheritanceTest.java +++ b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/rule/FilePlanRuleInheritanceTest.java @@ -66,10 +66,10 @@ public class FilePlanRuleInheritanceTest extends BaseRMTestCase } /** - * Given that a singel rule is set on the parent folder of the file plan root + * Given that a single rule is set on the parent folder of the file plan root * And that it is configured to apply to children - * When we ask for the rules on the file plan, inclusing those inherited - * Then it will not include thos defined on the parent folder + * When we ask for the rules on the file plan, including those inherited + * Then it will not include those defined on the parent folder */ public void testFilePlanDoesNotInheritRulesFromParentFolder() {