diff --git a/config/alfresco/action-services-context.xml b/config/alfresco/action-services-context.xml
index 4bdec2f235..a3647ea7b6 100644
--- a/config/alfresco/action-services-context.xml
+++ b/config/alfresco/action-services-context.xml
@@ -725,6 +725,18 @@
+
+
+
+
+
+
+
+
+ false
+
+
+
diff --git a/source/java/org/alfresco/repo/rule/LinkRules.java b/source/java/org/alfresco/repo/rule/LinkRules.java
index cdf0bc2a7e..f317a966e2 100644
--- a/source/java/org/alfresco/repo/rule/LinkRules.java
+++ b/source/java/org/alfresco/repo/rule/LinkRules.java
@@ -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);
}
/**
diff --git a/source/java/org/alfresco/repo/rule/ReorderRules.java b/source/java/org/alfresco/repo/rule/ReorderRules.java
new file mode 100644
index 0000000000..14eb55914b
--- /dev/null
+++ b/source/java/org/alfresco/repo/rule/ReorderRules.java
@@ -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 .
+ */
+
+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 rules = (List)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 paramList)
+ {
+ paramList.add(new ParameterDefinitionImpl(
+ PARAM_RULES,
+ DataTypeDefinition.NODE_REF,
+ true,
+ getParamDisplayLabel(PARAM_RULES),
+ true));
+ }
+}
diff --git a/source/java/org/alfresco/repo/rule/RuleServiceImplTest.java b/source/java/org/alfresco/repo/rule/RuleServiceImplTest.java
index 1d0480c31f..7b29e8a950 100644
--- a/source/java/org/alfresco/repo/rule/RuleServiceImplTest.java
+++ b/source/java/org/alfresco/repo/rule/RuleServiceImplTest.java
@@ -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 ruleNodeRefs = new ArrayList(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 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));
}
}
diff --git a/source/java/org/alfresco/repo/rule/UnlinkRules.java b/source/java/org/alfresco/repo/rule/UnlinkRules.java
index 3f5b38ae0e..dbc2488503 100644
--- a/source/java/org/alfresco/repo/rule/UnlinkRules.java
+++ b/source/java/org/alfresco/repo/rule/UnlinkRules.java
@@ -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);
+ }
}
}
}