mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Link rules now automatically re-links
- Calling link rules on an already linked folder will automatically unlink from the exisiting folder before linking to the new one. - Unit tests updated git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@19049 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -21,8 +21,6 @@ package org.alfresco.repo.rule;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.text.html.parser.ContentModel;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.repo.action.ParameterDefinitionImpl;
|
||||
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
|
||||
@@ -31,6 +29,7 @@ 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 link the rules from one folder to another
|
||||
@@ -39,18 +38,27 @@ import org.alfresco.service.cmr.repository.NodeService;
|
||||
*/
|
||||
public class LinkRules extends ActionExecuterAbstractBase
|
||||
{
|
||||
/** Name and parameter constants */
|
||||
public static final String NAME = "link-rules";
|
||||
public static final String PARAM_LINK_FROM_NODE = "link_from_node";
|
||||
|
||||
/** Node service */
|
||||
private NodeService nodeService;
|
||||
|
||||
/** Runtime rule service */
|
||||
private RuntimeRuleService ruleService;
|
||||
|
||||
/**
|
||||
* @param ruleService rule service
|
||||
*/
|
||||
public void setRuleService(RuntimeRuleService ruleService)
|
||||
{
|
||||
this.ruleService = ruleService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nodeService node service
|
||||
*/
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
@@ -64,13 +72,6 @@ public class LinkRules extends ActionExecuterAbstractBase
|
||||
{
|
||||
if (nodeService.exists(actionedUponNodeRef) == true)
|
||||
{
|
||||
// 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);
|
||||
@@ -79,6 +80,26 @@ public class LinkRules extends ActionExecuterAbstractBase
|
||||
throw new AlfrescoRuntimeException("The link from node has no rules to link.");
|
||||
}
|
||||
|
||||
// Check whether the node already has rules or not
|
||||
if (nodeService.hasAspect(actionedUponNodeRef, RuleModel.ASPECT_RULES) == true)
|
||||
{
|
||||
// Check for a linked to node
|
||||
NodeRef linkedToNode = ((RuleService)ruleService).getLinkedToRuleNode(actionedUponNodeRef);
|
||||
if (linkedToNode == null)
|
||||
{
|
||||
// Can't link a node if it already has rules
|
||||
throw new AlfrescoRuntimeException("The current folder has rules and can not be linked to another folder.");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Unlink the folder, before relinking later to the specified node
|
||||
NodeRef ruleFolder = ruleService.getSavedRuleFolderAssoc(linkedToNode).getChildRef();
|
||||
nodeService.removeChild(actionedUponNodeRef, ruleFolder);
|
||||
nodeService.removeAspect(actionedUponNodeRef, RuleModel.ASPECT_RULES);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
Reference in New Issue
Block a user