diff --git a/config/alfresco/messages/webclient.properties b/config/alfresco/messages/webclient.properties index eebac6d525..4e171a5bb7 100644 --- a/config/alfresco/messages/webclient.properties +++ b/config/alfresco/messages/webclient.properties @@ -223,6 +223,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_success=The rules have been successfully reapplied. manage_rules=Manage Content Rules manage_users=Manage System Users manage_groups=Manage User Groups diff --git a/config/alfresco/web-client-config-actions.xml b/config/alfresco/web-client-config-actions.xml index 0b54950bec..1233076456 100644 --- a/config/alfresco/web-client-config-actions.xml +++ b/config/alfresco/web-client-config-actions.xml @@ -459,6 +459,13 @@ + + + reapply_rules + /images/icons/export.gif + #{RulesBean.reapplyRules} + + @@ -594,6 +601,11 @@ + + + + + diff --git a/source/java/org/alfresco/web/bean/rules/RulesBean.java b/source/java/org/alfresco/web/bean/rules/RulesBean.java index 00f8140f48..de3cbecc77 100644 --- a/source/java/org/alfresco/web/bean/rules/RulesBean.java +++ b/source/java/org/alfresco/web/bean/rules/RulesBean.java @@ -16,14 +16,20 @@ */ package org.alfresco.web.bean.rules; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; +import javax.faces.application.FacesMessage; import javax.faces.context.FacesContext; import javax.faces.event.ActionEvent; +import javax.transaction.UserTransaction; +import org.alfresco.repo.action.executer.ExecuteAllRulesActionExecuter; +import org.alfresco.service.cmr.action.Action; +import org.alfresco.service.cmr.action.ActionService; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.rule.Rule; import org.alfresco.service.cmr.rule.RuleService; @@ -32,6 +38,7 @@ import org.alfresco.web.app.context.IContextListener; import org.alfresco.web.app.context.UIContextService; import org.alfresco.web.bean.BrowseBean; import org.alfresco.web.bean.repository.Node; +import org.alfresco.web.bean.repository.Repository; import org.alfresco.web.ui.common.Utils; import org.alfresco.web.ui.common.component.UIActionLink; import org.alfresco.web.ui.common.component.UIModeList; @@ -47,6 +54,7 @@ import org.apache.commons.logging.LogFactory; public class RulesBean implements IContextListener { private static final String MSG_ERROR_DELETE_RULE = "error_delete_rule"; + private static final String MSG_REAPPLY_RULES_SUCCESS = "reapply_rules_success"; private static final String LOCAL = "local"; private static final String INHERITED = "inherited"; @@ -58,6 +66,7 @@ public class RulesBean implements IContextListener private List rules; private Rule currentRule; private UIRichList richList; + private ActionService actionService; /** @@ -137,6 +146,53 @@ public class RulesBean implements IContextListener } } + /** + * Reapply the currently defines rules to the + * @param event + */ + public void reapplyRules(ActionEvent event) + { + FacesContext fc = FacesContext.getCurrentInstance(); + + UserTransaction tx = null; + + try + { + tx = Repository.getUserTransaction(fc); + tx.begin(); + + // Create the the apply rules action + Action action = this.actionService.createAction(ExecuteAllRulesActionExecuter.NAME); + + // Set the include inherited parameter to match the current filter value + boolean executeInherited = true; + if (LOCAL.equals(this.getViewMode()) == true) + { + executeInherited = false; + } + action.setParameterValue(ExecuteAllRulesActionExecuter.PARAM_EXECUTE_INHERITED_RULES, executeInherited); + + // Execute the action + this.actionService.executeAction(action, this.getSpace().getNodeRef()); + + // TODO how do I get the message here ... + String msg = Application.getMessage(fc, MSG_REAPPLY_RULES_SUCCESS); + FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_INFO, msg, msg); + String formId = Utils.getParentForm(fc, event.getComponent()).getClientId(fc); + fc.addMessage(formId + ":rulesList", facesMsg); + + // commit the transaction + tx.commit(); + } + catch (Throwable e) + { + // rollback the transaction + try { if (tx != null) {tx.rollback();} } catch (Exception ex) {} + Utils.addErrorMessage(MessageFormat.format(Application.getMessage( + fc, Repository.ERROR_GENERIC), e.getMessage()), e); + } + } + /** * Returns the current rule * @@ -240,6 +296,16 @@ public class RulesBean implements IContextListener { this.ruleService = ruleService; } + + /** + * Set the action service to use + * + * @param actionService the action service + */ + public void setActionService(ActionService actionService) + { + this.actionService = actionService; + } // ------------------------------------------------------------------------------ diff --git a/source/web/WEB-INF/faces-config-beans.xml b/source/web/WEB-INF/faces-config-beans.xml index 0290414ab2..68ddab424f 100644 --- a/source/web/WEB-INF/faces-config-beans.xml +++ b/source/web/WEB-INF/faces-config-beans.xml @@ -887,6 +887,10 @@ ruleService #{RuleService} + + actionService + #{ActionService} + diff --git a/source/web/jsp/dialog/rules.jsp b/source/web/jsp/dialog/rules.jsp index aaafc07119..4cc77466e7 100644 --- a/source/web/jsp/dialog/rules.jsp +++ b/source/web/jsp/dialog/rules.jsp @@ -75,8 +75,14 @@ <%-- Current object actions --%> + + + <%-- More actions menu --%> + + + - + <%-- Filters --%> - +