mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
- Added execute all rules action
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2771 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -347,4 +347,19 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="execute-all-rules" class="org.alfresco.repo.action.executer.ExecuteAllRulesActionExecuter" parent="action-executer">
|
||||
<property name="nodeService">
|
||||
<ref bean="NodeService" />
|
||||
</property>
|
||||
<property name="actionService">
|
||||
<ref bean="ActionService" />
|
||||
</property>
|
||||
<property name="ruleService">
|
||||
<ref bean="RuleService" />
|
||||
</property>
|
||||
<property name="dictionaryService">
|
||||
<ref bean="DictionaryService" />
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
@@ -74,3 +74,6 @@ export.package.error=Failed to find temporary file for export
|
||||
|
||||
script.title=Execute a script
|
||||
script.description=Execute a JavaScript file to perform tasks such as creating new files or folders
|
||||
|
||||
execute-all-rules.title=Execute all rules
|
||||
execute-all-rules.description=Execute all rules on the child items
|
||||
|
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.repo.action.executer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.action.ParameterDefinitionImpl;
|
||||
import org.alfresco.service.cmr.action.Action;
|
||||
import org.alfresco.service.cmr.action.ActionService;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 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";
|
||||
|
||||
/**
|
||||
* The node service
|
||||
*/
|
||||
private NodeService nodeService;
|
||||
|
||||
/**
|
||||
* The rule service
|
||||
*/
|
||||
private RuleService ruleService;
|
||||
|
||||
/**
|
||||
* The action service
|
||||
*/
|
||||
private ActionService actionService;
|
||||
|
||||
/** 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 action service
|
||||
*
|
||||
* @param actionService the action service
|
||||
*/
|
||||
public void setActionService(ActionService actionService)
|
||||
{
|
||||
this.actionService = actionService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(org.alfresco.service.cmr.repository.NodeRef, 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();
|
||||
}
|
||||
|
||||
// Get the rules
|
||||
List<Rule> rules = this.ruleService.getRules(actionedUponNodeRef, includeInherited);
|
||||
if (rules != null && rules.isEmpty() == false)
|
||||
{
|
||||
// Get the child nodes for the actioned upon node
|
||||
List<ChildAssociationRef> children = this.nodeService.getChildAssocs(actionedUponNodeRef);
|
||||
for (ChildAssociationRef childAssoc : children)
|
||||
{
|
||||
// Get the child node reference
|
||||
NodeRef child = childAssoc.getChildRef();
|
||||
|
||||
// Only execute rules on non-system folders
|
||||
if (this.dictionaryService.isSubClass(this.nodeService.getType(child), ContentModel.TYPE_SYSTEM_FOLDER) == false)
|
||||
{
|
||||
for (Rule rule : rules)
|
||||
{
|
||||
// Apply the rule to the child node
|
||||
this.actionService.executeAction(rule, child);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefintions(java.util.List)
|
||||
*/
|
||||
@Override
|
||||
protected void addParameterDefintions(List<ParameterDefinition> paramList)
|
||||
{
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_EXECUTE_INHERITED_RULES, DataTypeDefinition.BOOLEAN, false, getParamDisplayLabel(PARAM_EXECUTE_INHERITED_RULES)));
|
||||
}
|
||||
}
|
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.repo.action.executer;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.action.ActionImpl;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||
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.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.rule.Rule;
|
||||
import org.alfresco.service.cmr.rule.RuleService;
|
||||
import org.alfresco.service.cmr.rule.RuleType;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.BaseSpringTest;
|
||||
import org.alfresco.util.GUID;
|
||||
|
||||
/**
|
||||
* Execute all rules action execution test
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class ExecuteAllRulesActionExecuterTest extends BaseSpringTest
|
||||
{
|
||||
/** The node service */
|
||||
private NodeService nodeService;
|
||||
|
||||
/** The rule service */
|
||||
private RuleService ruleService;
|
||||
|
||||
/** The action service */
|
||||
private ActionService actionService;
|
||||
|
||||
/** The store reference */
|
||||
private StoreRef testStoreRef;
|
||||
|
||||
/** The root node reference */
|
||||
private NodeRef rootNodeRef;
|
||||
|
||||
/** The add features action executer */
|
||||
private ExecuteAllRulesActionExecuter executer;
|
||||
|
||||
/** Id used to identify the test action created */
|
||||
private final static String ID = GUID.generate();
|
||||
|
||||
/**
|
||||
* Called at the begining of all tests
|
||||
*/
|
||||
@Override
|
||||
protected void onSetUpInTransaction() throws Exception
|
||||
{
|
||||
this.nodeService = (NodeService)this.applicationContext.getBean("nodeService");
|
||||
this.ruleService = (RuleService)this.applicationContext.getBean("ruleService");
|
||||
this.actionService = (ActionService)this.applicationContext.getBean("actionService");
|
||||
|
||||
AuthenticationComponent authenticationComponent = (AuthenticationComponent)applicationContext.getBean("authenticationComponent");
|
||||
authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
|
||||
|
||||
// Create the store and get the root node
|
||||
this.testStoreRef = this.nodeService.createStore(
|
||||
StoreRef.PROTOCOL_WORKSPACE, "Test_"
|
||||
+ System.currentTimeMillis());
|
||||
this.rootNodeRef = this.nodeService.getRootNode(this.testStoreRef);
|
||||
|
||||
// Get the executer instance
|
||||
this.executer = (ExecuteAllRulesActionExecuter)this.applicationContext.getBean(ExecuteAllRulesActionExecuter.NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test execution
|
||||
*/
|
||||
public void testExecution()
|
||||
{
|
||||
// Create a folder and put a couple of documents in it
|
||||
NodeRef folder = this.nodeService.createNode(
|
||||
this.rootNodeRef,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
QName.createQName("{test}folderOne"),
|
||||
ContentModel.TYPE_FOLDER).getChildRef();
|
||||
NodeRef doc1 = this.nodeService.createNode(
|
||||
folder,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
QName.createQName("{test}docOne"),
|
||||
ContentModel.TYPE_CONTENT).getChildRef();
|
||||
NodeRef doc2 = this.nodeService.createNode(
|
||||
folder,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
QName.createQName("{test}docTwo"),
|
||||
ContentModel.TYPE_CONTENT).getChildRef();
|
||||
|
||||
// Add a couple of rules to the folder
|
||||
Rule rule1 = this.ruleService.createRule(RuleType.INBOUND);
|
||||
Action action1 = this.actionService.createAction(AddFeaturesActionExecuter.NAME);
|
||||
action1.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_VERSIONABLE);
|
||||
rule1.addAction(action1);
|
||||
this.ruleService.saveRule(folder, rule1);
|
||||
Rule rule2 = this.ruleService.createRule(RuleType.INBOUND);
|
||||
Action action2 = this.actionService.createAction(AddFeaturesActionExecuter.NAME);
|
||||
action2.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_CLASSIFIABLE);
|
||||
rule2.addAction(action2);
|
||||
this.ruleService.saveRule(folder, rule2);
|
||||
|
||||
// Check the the docs don't have the aspects yet
|
||||
assertFalse(this.nodeService.hasAspect(doc1, ContentModel.ASPECT_VERSIONABLE));
|
||||
assertFalse(this.nodeService.hasAspect(doc1, ContentModel.ASPECT_CLASSIFIABLE));
|
||||
assertFalse(this.nodeService.hasAspect(doc2, ContentModel.ASPECT_VERSIONABLE));
|
||||
assertFalse(this.nodeService.hasAspect(doc2, ContentModel.ASPECT_CLASSIFIABLE));
|
||||
|
||||
assertTrue(this.nodeService.exists(folder));
|
||||
|
||||
// Execute the action
|
||||
ActionImpl action = new ActionImpl(ID, ExecuteAllRulesActionExecuter.NAME, null);
|
||||
this.executer.execute(action, folder);
|
||||
|
||||
assertTrue(this.nodeService.hasAspect(doc1, ContentModel.ASPECT_VERSIONABLE));
|
||||
assertTrue(this.nodeService.hasAspect(doc1, ContentModel.ASPECT_CLASSIFIABLE));
|
||||
assertTrue(this.nodeService.hasAspect(doc2, ContentModel.ASPECT_VERSIONABLE));
|
||||
assertTrue(this.nodeService.hasAspect(doc2, ContentModel.ASPECT_CLASSIFIABLE));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user