Added reordering action

- the actioned upon node is the node that has the rules
- the rule nodes are provided as a multi-value property (list of node refs) and then reordered in the order found on the list
- additional existance checks where added to the link/unlink actions



git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@18934 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Roy Wetherall
2010-03-02 00:27:35 +00:00
parent cefda8c965
commit 7d80cb0867
5 changed files with 173 additions and 28 deletions

View File

@@ -725,6 +725,18 @@
</property>
</bean>
<bean id="reorder-rules" class="org.alfresco.repo.rule.ReorderRules" parent="action-executer">
<property name="nodeService">
<ref bean="NodeService"/>
</property>
<property name="ruleService">
<ref bean="ruleService"/>
</property>
<property name="publicAction">
<value>false</value>
</property>
</bean>
<!-- deprecated -->
<bean id="avm-link-validation" class="org.alfresco.linkvalidation.LinkValidationAction" parent="action-executer" lazy-init="true">
<property name="linkValidationService">

View File

@@ -62,25 +62,28 @@ public class LinkRules extends ActionExecuterAbstractBase
@Override
protected void executeImpl(Action action, NodeRef actionedUponNodeRef)
{
// The actioned upon node is the rule folder we are interested in
// this should not already have rules associated with it
if (nodeService.hasAspect(actionedUponNodeRef, RuleModel.ASPECT_RULES) == true)
if (nodeService.exists(actionedUponNodeRef) == true)
{
throw new AlfrescoRuntimeException("The link to node already has rules.");
// The actioned upon node is the rule folder we are interested in
// this should not already have rules associated with it
if (nodeService.hasAspect(actionedUponNodeRef, RuleModel.ASPECT_RULES) == true)
{
throw new AlfrescoRuntimeException("The link to node already has rules.");
}
// Link to folder is passed as a parameter
// this should have rules already specified
NodeRef linkedFromNodeRef = (NodeRef)action.getParameterValue(PARAM_LINK_FROM_NODE);
if (nodeService.hasAspect(linkedFromNodeRef, RuleModel.ASPECT_RULES) == false)
{
throw new AlfrescoRuntimeException("The link from node has no rules to link.");
}
// Create the destination folder as a secondary child of the first
NodeRef ruleSetNodeRef = ruleService.getSavedRuleFolderAssoc(linkedFromNodeRef).getChildRef();
nodeService.addChild(actionedUponNodeRef, ruleSetNodeRef, RuleModel.ASSOC_RULE_FOLDER, RuleModel.ASSOC_RULE_FOLDER);
nodeService.addAspect(actionedUponNodeRef, RuleModel.ASPECT_RULES, null);
}
// Link to folder is passed as a parameter
// this should have rules already specified
NodeRef linkedFromNodeRef = (NodeRef)action.getParameterValue(PARAM_LINK_FROM_NODE);
if (nodeService.hasAspect(linkedFromNodeRef, RuleModel.ASPECT_RULES) == false)
{
throw new AlfrescoRuntimeException("The link from node has no rules to link.");
}
// Create the destination folder as a secondary child of the first
NodeRef ruleSetNodeRef = ruleService.getSavedRuleFolderAssoc(linkedFromNodeRef).getChildRef();
nodeService.addChild(actionedUponNodeRef, ruleSetNodeRef, RuleModel.ASSOC_RULE_FOLDER, RuleModel.ASSOC_RULE_FOLDER);
nodeService.addAspect(actionedUponNodeRef, RuleModel.ASPECT_RULES, null);
}
/**

View File

@@ -0,0 +1,107 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* 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/>.
*/
package org.alfresco.repo.rule;
import java.util.List;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
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.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.rule.RuleService;
/**
* Action implementation to reorder rules
*
* @author Roy Wetherall
*/
public class ReorderRules extends ActionExecuterAbstractBase
{
/** Constants */
public static final String NAME = "reorder-rules";
public static final String PARAM_RULES = "rules";
/** Node service */
private NodeService nodeService;
/** Rule service */
private RuleService ruleService;
/**
* Set rule service
*
* @param ruleService rule service
*/
public void setRuleService(RuleService ruleService)
{
this.ruleService = ruleService;
}
/**
* Set node service
*
* @param nodeService node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef)
*/
@SuppressWarnings("unchecked")
@Override
protected void executeImpl(Action action, NodeRef actionedUponNodeRef)
{
if (nodeService.exists(actionedUponNodeRef) == true)
{
// Check that the actioned upon node has the rules aspect applied
if (nodeService.hasAspect(actionedUponNodeRef, RuleModel.ASPECT_RULES) == true)
{
List<NodeRef> rules = (List<NodeRef>)action.getParameterValue(PARAM_RULES);
int index = 0;
for (NodeRef rule : rules)
{
ruleService.setRulePosition(actionedUponNodeRef, rule, index);
index++;
}
}
}
}
/**
* @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefinitions(java.util.List)
*/
@Override
protected void addParameterDefinitions(List<ParameterDefinition> paramList)
{
paramList.add(new ParameterDefinitionImpl(
PARAM_RULES,
DataTypeDefinition.NODE_REF,
true,
getParamDisplayLabel(PARAM_RULES),
true));
}
}

View File

@@ -20,6 +20,7 @@ package org.alfresco.repo.rule;
import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -269,7 +270,26 @@ public class RuleServiceImplTest extends BaseRuleTest
{
System.out.println(" - Assoc index = " + ruleChildAssocRef.getNthSibling() + ", name = " +
nodeService.getProperty(ruleChildAssocRef.getChildRef(), ContentModel.PROP_TITLE));
}
}
}
List<NodeRef> ruleNodeRefs = new ArrayList<NodeRef>(rules.size());
for (Rule tempRule : rules)
{
ruleNodeRefs.add(0, tempRule.getNodeRef());
}
Action action = actionService.createAction(ReorderRules.NAME);
action.setParameterValue(ReorderRules.PARAM_RULES, (Serializable)ruleNodeRefs);
actionService.executeAction(action, nodeRef);
List<ChildAssociationRef> ruleChildAssocRefs = nodeService.getChildAssocs(ruleFolder, RegexQNamePattern.MATCH_ALL, ASSOC_NAME_RULES_REGEX);
System.out.println("After execution of action ...");
for (ChildAssociationRef ruleChildAssocRef : ruleChildAssocRefs)
{
System.out.println(" - Assoc index = " + ruleChildAssocRef.getNthSibling() + ", name = " +
nodeService.getProperty(ruleChildAssocRef.getChildRef(), ContentModel.PROP_TITLE));
}
}

View File

@@ -70,16 +70,19 @@ public class UnlinkRules extends ActionExecuterAbstractBase
@Override
protected void executeImpl(Action action, NodeRef actionedUponNodeRef)
{
// Check that the actioned upon node has the rules aspect applied
if (nodeService.hasAspect(actionedUponNodeRef, RuleModel.ASPECT_RULES) == true)
{
// Get the rule node the actioned upon node is linked to
NodeRef linkedToNode = ((RuleService)ruleService).getLinkedToRuleNode(actionedUponNodeRef);
if (linkedToNode != null)
{
NodeRef ruleFolder = ruleService.getSavedRuleFolderAssoc(linkedToNode).getChildRef();
nodeService.removeChild(actionedUponNodeRef, ruleFolder);
nodeService.removeAspect(actionedUponNodeRef, RuleModel.ASPECT_RULES);
if (nodeService.exists(actionedUponNodeRef) == true)
{
// Check that the actioned upon node has the rules aspect applied
if (nodeService.hasAspect(actionedUponNodeRef, RuleModel.ASPECT_RULES) == true)
{
// Get the rule node the actioned upon node is linked to
NodeRef linkedToNode = ((RuleService)ruleService).getLinkedToRuleNode(actionedUponNodeRef);
if (linkedToNode != null)
{
NodeRef ruleFolder = ruleService.getSavedRuleFolderAssoc(linkedToNode).getChildRef();
nodeService.removeChild(actionedUponNodeRef, ruleFolder);
nodeService.removeAspect(actionedUponNodeRef, RuleModel.ASPECT_RULES);
}
}
}
}