mirror of
				https://github.com/Alfresco/alfresco-community-repo.git
				synced 2025-10-29 15:21:53 +00:00 
			
		
		
		
	125788 rmunteanu: Merged 5.1.N (5.1.2) to 5.2.N (5.2.1)
      125606 rmunteanu: Merged 5.1.1 (5.1.1) to 5.1.N (5.1.2)
         125515 slanglois: MNT-16155 Update source headers - add new Copyrights for Java and JSP source files + automatic check in the build
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@127810 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
		
	
		
			
				
	
	
		
			189 lines
		
	
	
		
			7.0 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			189 lines
		
	
	
		
			7.0 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
/*
 | 
						|
 * #%L
 | 
						|
 * Alfresco Repository
 | 
						|
 * %%
 | 
						|
 * Copyright (C) 2005 - 2016 Alfresco Software Limited
 | 
						|
 * %%
 | 
						|
 * This file is part of the Alfresco software. 
 | 
						|
 * If the software was purchased under a paid Alfresco license, the terms of 
 | 
						|
 * the paid license agreement will prevail.  Otherwise, the software is 
 | 
						|
 * provided under the following open source license terms:
 | 
						|
 * 
 | 
						|
 * Alfresco is free software: you can redistribute it and/or modify
 | 
						|
 * it under the terms of the GNU Lesser General Public License as published by
 | 
						|
 * the Free Software Foundation, either version 3 of the License, or
 | 
						|
 * (at your option) any later version.
 | 
						|
 * 
 | 
						|
 * Alfresco is distributed in the hope that it will be useful,
 | 
						|
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
						|
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
						|
 * GNU Lesser General Public License for more details.
 | 
						|
 * 
 | 
						|
 * You should have received a copy of the GNU Lesser General Public License
 | 
						|
 * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
 | 
						|
 * #L%
 | 
						|
 */
 | 
						|
package org.alfresco.repo.action.executer;
 | 
						|
 | 
						|
import java.util.List;
 | 
						|
 | 
						|
import org.alfresco.model.ContentModel;
 | 
						|
import org.alfresco.repo.action.ParameterDefinitionImpl;
 | 
						|
import org.alfresco.repo.rule.RuntimeRuleService;
 | 
						|
import org.alfresco.service.cmr.action.Action;
 | 
						|
import org.alfresco.service.cmr.action.ParameterDefinition;
 | 
						|
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
 | 
						|
import org.alfresco.service.cmr.dictionary.DictionaryService;
 | 
						|
import org.alfresco.service.cmr.repository.ChildAssociationRef;
 | 
						|
import org.alfresco.service.cmr.repository.NodeRef;
 | 
						|
import org.alfresco.service.cmr.repository.NodeService;
 | 
						|
import org.alfresco.service.cmr.rule.Rule;
 | 
						|
import org.alfresco.service.cmr.rule.RuleService;
 | 
						|
import org.alfresco.service.namespace.QName;
 | 
						|
 | 
						|
/**
 | 
						|
 * This action executes all rules present on the actioned upon node 
 | 
						|
 * 
 | 
						|
 * @author Roy Wetherall
 | 
						|
 */
 | 
						|
public class ExecuteAllRulesActionExecuter extends ActionExecuterAbstractBase
 | 
						|
{
 | 
						|
    /**
 | 
						|
     * Action constants
 | 
						|
     */
 | 
						|
	public static final String NAME = "execute-all-rules";
 | 
						|
    public static final String PARAM_EXECUTE_INHERITED_RULES = "execute-inherited-rules";
 | 
						|
    public static final String PARAM_RUN_ALL_RULES_ON_CHILDREN = "run-all-rules-on-children";
 | 
						|
	
 | 
						|
	/**
 | 
						|
	 * The node service
 | 
						|
	 */
 | 
						|
	private NodeService nodeService;
 | 
						|
    
 | 
						|
    /**
 | 
						|
     * The rule service
 | 
						|
     */
 | 
						|
    private RuleService ruleService;
 | 
						|
    
 | 
						|
    /**
 | 
						|
     * The runtime rule service
 | 
						|
     */
 | 
						|
    private RuntimeRuleService runtimeRuleService;
 | 
						|
    
 | 
						|
    /** The dictionary Service */
 | 
						|
    private DictionaryService dictionaryService;
 | 
						|
	
 | 
						|
    /**
 | 
						|
     * Set the node service
 | 
						|
     * 
 | 
						|
     * @param nodeService  the node service
 | 
						|
     */
 | 
						|
	public void setNodeService(NodeService nodeService) 
 | 
						|
	{
 | 
						|
		this.nodeService = nodeService;
 | 
						|
	}
 | 
						|
    
 | 
						|
    /**
 | 
						|
     * Set the rule service
 | 
						|
     * 
 | 
						|
     * @param ruleService   the rule service
 | 
						|
     */
 | 
						|
    public void setRuleService(RuleService ruleService)
 | 
						|
    {
 | 
						|
        this.ruleService = ruleService;
 | 
						|
    }
 | 
						|
    
 | 
						|
    /**
 | 
						|
     * Set the runtime rule service
 | 
						|
     * 
 | 
						|
     * @param runtimeRuleService the runtime rule service
 | 
						|
     */
 | 
						|
    public void setRuntimeRuleService(RuntimeRuleService runtimeRuleService)
 | 
						|
    {
 | 
						|
       this.runtimeRuleService = runtimeRuleService;
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Sets the dictionary service
 | 
						|
     * 
 | 
						|
     * @param dictionaryService     the dictionary service
 | 
						|
     */
 | 
						|
    public void setDictionaryService(DictionaryService dictionaryService)
 | 
						|
    {
 | 
						|
        this.dictionaryService = dictionaryService;
 | 
						|
    }
 | 
						|
    
 | 
						|
    /**
 | 
						|
     * @see org.alfresco.repo.action.executer.ActionExecuter#execute(Action, NodeRef)
 | 
						|
     */
 | 
						|
    public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef)
 | 
						|
    {
 | 
						|
		if (this.nodeService.exists(actionedUponNodeRef) == true)
 | 
						|
		{
 | 
						|
            // Get the parameter value
 | 
						|
            boolean includeInherited = false;
 | 
						|
            Boolean includeInheritedValue = (Boolean)ruleAction.getParameterValue(PARAM_EXECUTE_INHERITED_RULES);
 | 
						|
            if (includeInheritedValue != null)
 | 
						|
            {
 | 
						|
                includeInherited = includeInheritedValue.booleanValue();
 | 
						|
            }
 | 
						|
            
 | 
						|
            boolean runAllChildren = false;
 | 
						|
            Boolean runAllChildrenValue = (Boolean)ruleAction.getParameterValue(PARAM_RUN_ALL_RULES_ON_CHILDREN);
 | 
						|
            if (runAllChildrenValue != null)
 | 
						|
            {
 | 
						|
                runAllChildren = runAllChildrenValue.booleanValue();
 | 
						|
            }
 | 
						|
            
 | 
						|
		    // Get the rules
 | 
						|
            List<Rule> rules = ruleService.getRules(actionedUponNodeRef, includeInherited);
 | 
						|
            if (rules != null && rules.isEmpty() == false)
 | 
						|
            {
 | 
						|
                // 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)
 | 
						|
                           {
 | 
						|
                               Action action = rule.getAction();
 | 
						|
                               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 &&
 | 
						|
                            dictionaryService.isSubClass(childType, ContentModel.TYPE_FOLDER) == true)
 | 
						|
                        {
 | 
						|
                            // Recurse with the child folder
 | 
						|
                            executeImpl(ruleAction, child);
 | 
						|
                        }
 | 
						|
                    }                    
 | 
						|
                }
 | 
						|
            }
 | 
						|
		}
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefinitions(java.util.List)
 | 
						|
     */
 | 
						|
    @Override
 | 
						|
    protected void addParameterDefinitions(List<ParameterDefinition> paramList)
 | 
						|
    {
 | 
						|
        paramList.add(new ParameterDefinitionImpl(PARAM_EXECUTE_INHERITED_RULES, DataTypeDefinition.BOOLEAN, false, getParamDisplayLabel(PARAM_EXECUTE_INHERITED_RULES)));
 | 
						|
        paramList.add(new ParameterDefinitionImpl(PARAM_RUN_ALL_RULES_ON_CHILDREN, DataTypeDefinition.BOOLEAN, false, getParamDisplayLabel(PARAM_RUN_ALL_RULES_ON_CHILDREN)));
 | 
						|
    }
 | 
						|
}
 |