From 218cb33e75f8b5318c49d75b86514dea8ff48072 Mon Sep 17 00:00:00 2001 From: Roy Wetherall Date: Tue, 26 Feb 2008 16:35:04 +0000 Subject: [PATCH] Merged V2.2 to HEAD 7461: Reapply rules to children and other rule related fixes git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@8385 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/messages/webclient.properties | 3 +- config/alfresco/web-client-config-actions.xml | 40 ++++++-------- .../alfresco/web/bean/rules/RulesDialog.java | 52 +++++++++++++++---- 3 files changed, 59 insertions(+), 36 deletions(-) diff --git a/config/alfresco/messages/webclient.properties b/config/alfresco/messages/webclient.properties index 6428272a14..866fb9dbd6 100644 --- a/config/alfresco/messages/webclient.properties +++ b/config/alfresco/messages/webclient.properties @@ -347,7 +347,8 @@ add_multiple_files=Add Multiple Files import_directory=Import Directory advanced_space_wizard=Advanced Space Wizard create_rule=Create Rule -reapply_rules=Reapply Rules +reapply_rules=Reapply Rules In Space +reapply_rules_to_children=Reapply Rules in Space and Children reapply_rules_success=The rules have been successfully reapplied. ignore_inherited_rules=Ignore Inherited Rules include_inherited_rules=Include Inherited Rules diff --git a/config/alfresco/web-client-config-actions.xml b/config/alfresco/web-client-config-actions.xml index e89928585e..0d0c66eb7b 100644 --- a/config/alfresco/web-client-config-actions.xml +++ b/config/alfresco/web-client-config-actions.xml @@ -638,7 +638,19 @@ reapply_rules /images/icons/reapply_rules.gif - #{RulesDialog.reapplyRules} + #{RulesDialog.reapplyRules} + + False + + + + + reapply_rules_to_children + /images/icons/reapply_rules.gif + #{RulesDialog.reapplyRules} + + True + @@ -728,22 +740,7 @@ create_rule /images/icons/new_rule.gif wizard:createRule - - - - - reapply_rules - /images/icons/reapply_rules.gif - #{RulesDialog.reapplyRules} - - - - - - /images/icons/reapply_rules.gif - #{RulesDialog.ignoreInheritedRules} - - + @@ -1034,7 +1031,8 @@ - + + @@ -1085,12 +1083,6 @@ - - - - - - diff --git a/source/java/org/alfresco/web/bean/rules/RulesDialog.java b/source/java/org/alfresco/web/bean/rules/RulesDialog.java index c596dc0e5d..45724dc8a6 100644 --- a/source/java/org/alfresco/web/bean/rules/RulesDialog.java +++ b/source/java/org/alfresco/web/bean/rules/RulesDialog.java @@ -41,9 +41,12 @@ import org.alfresco.repo.action.executer.ExecuteAllRulesActionExecuter; import org.alfresco.repo.rule.RuleModel; import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.ActionService; +import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.rule.Rule; import org.alfresco.service.cmr.rule.RuleService; +import org.alfresco.service.namespace.QName; +import org.alfresco.service.namespace.RegexQNamePattern; import org.alfresco.web.app.Application; import org.alfresco.web.app.context.IContextListener; import org.alfresco.web.app.context.UIContextService; @@ -85,8 +88,7 @@ public class RulesDialog extends BaseDialogBean implements IContextListener, Fil private List rules; transient private Rule currentRule; private UIRichList richList; - transient private ActionService actionService; - + transient private ActionService actionService; /** * Default constructor @@ -176,8 +178,16 @@ public class RulesDialog extends BaseDialogBean implements IContextListener, Fil */ public void reapplyRules(ActionEvent event) { - FacesContext fc = FacesContext.getCurrentInstance(); - + boolean toChildren = false; + UIActionLink link = (UIActionLink)event.getComponent(); + Map params = link.getParameterMap(); + String toChildrenStr = params.get("toChildren"); + if (toChildrenStr != null) + { + toChildren = new Boolean(toChildrenStr).booleanValue(); + } + + FacesContext fc = FacesContext.getCurrentInstance(); UserTransaction tx = null; try @@ -185,19 +195,15 @@ public class RulesDialog extends BaseDialogBean implements IContextListener, Fil tx = Repository.getUserTransaction(fc); tx.begin(); - // Create the the apply rules action - Action action = this.getActionService().createAction(ExecuteAllRulesActionExecuter.NAME); - // Set the include inherited parameter to match the current filter value boolean executeInherited = true; - if (LOCAL.equals(this.getFilterMode()) == true) + if (this.filterModeMode.equals(LOCAL)) { executeInherited = false; } - action.setParameterValue(ExecuteAllRulesActionExecuter.PARAM_EXECUTE_INHERITED_RULES, executeInherited); - // Execute the action - this.getActionService().executeAction(action, this.getSpace().getNodeRef()); + // Reapply the rules + reapplyRules(this.getSpace().getNodeRef(), executeInherited, toChildren); // TODO how do I get the message here ... String msg = Application.getMessage(fc, MSG_REAPPLY_RULES_SUCCESS); @@ -217,6 +223,30 @@ public class RulesDialog extends BaseDialogBean implements IContextListener, Fil } } + private void reapplyRules(NodeRef space, boolean executeInherited, boolean toChildren) + { + // Create the the apply rules action + Action action = this.getActionService().createAction(ExecuteAllRulesActionExecuter.NAME); + action.setParameterValue(ExecuteAllRulesActionExecuter.PARAM_EXECUTE_INHERITED_RULES, executeInherited); + + // Execute the action + this.getActionService().executeAction(action, space); + + if (toChildren == true) + { + List assocs = getNodeService().getChildAssocs(space, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL); + for (ChildAssociationRef assoc : assocs) + { + NodeRef nodeRef = assoc.getChildRef(); + QName className = getNodeService().getType(nodeRef); + if (getDictionaryService().isSubClass(className, ContentModel.TYPE_FOLDER) == true) + { + reapplyRules(nodeRef, executeInherited, toChildren); + } + } + } + } + /** * Gets the label id from the ignore inhertied action *