mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
ACS-3489 Use specified rule set. (#1373)
* ACS-3280 Get inherited rule sets. [tas] This needs to work the exact same way as get inherited rules. * ACS-3280 Replace LinkedList with ArrayList. * ACS-3280 Don't return duplicated rule sets when there are links. * ACS-3489 E2E test for getting rules with inheritance. * ACS-3489 Inherited rule sets are also associated with folders. * ACS-3489 Fix test to contain expected values. * ACS-3489 Ensure only rules from specified rule set are returned. Add E2E test case for inherited links and fix unit tests. * ACS-3489 Fix audit reference in RuleService.
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
package org.alfresco.repo.rule;
|
||||
|
||||
import static org.alfresco.repo.rule.RuleModel.ASPECT_IGNORE_INHERITED_RULES;
|
||||
import static org.alfresco.repo.rule.RuleModel.ASSOC_RULE_FOLDER;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
@@ -35,6 +36,9 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.action.ActionImpl;
|
||||
@@ -257,7 +261,7 @@ public class RuleServiceImpl
|
||||
policyComponent.bindAssociationBehaviour(
|
||||
NodeServicePolicies.OnCreateChildAssociationPolicy.QNAME,
|
||||
RuleModel.ASPECT_RULES,
|
||||
RuleModel.ASSOC_RULE_FOLDER,
|
||||
ASSOC_RULE_FOLDER,
|
||||
new JavaBehaviour(this, "onCreateChildAssociation"));
|
||||
policyComponent.bindClassBehaviour(
|
||||
NodeServicePolicies.OnAddAspectPolicy.QNAME,
|
||||
@@ -349,8 +353,8 @@ public class RuleServiceImpl
|
||||
|
||||
List<ChildAssociationRef> assocs = this.runtimeNodeService.getChildAssocs(
|
||||
nodeRef,
|
||||
RuleModel.ASSOC_RULE_FOLDER,
|
||||
RuleModel.ASSOC_RULE_FOLDER);
|
||||
ASSOC_RULE_FOLDER,
|
||||
ASSOC_RULE_FOLDER);
|
||||
if (assocs.size() > 1)
|
||||
{
|
||||
throw new ActionServiceException("There is more than one rule folder, which is invalid.");
|
||||
@@ -1568,6 +1572,12 @@ public class RuleServiceImpl
|
||||
return this.nodeService.getPrimaryParent(systemFolder).getParentRef();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeRef getOwningNodeRef(NodeRef ruleSet)
|
||||
{
|
||||
return nodeService.getPrimaryParent(ruleSet).getParentRef();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeRef getOwningNodeRef(final Action action)
|
||||
{
|
||||
@@ -1660,7 +1670,7 @@ public class RuleServiceImpl
|
||||
@Experimental
|
||||
public NodeRef getRuleSetNode(final NodeRef folderNodeRef)
|
||||
{
|
||||
return runtimeNodeService.getChildAssocs(folderNodeRef, RuleModel.ASSOC_RULE_FOLDER, RuleModel.ASSOC_RULE_FOLDER).stream()
|
||||
return runtimeNodeService.getChildAssocs(folderNodeRef, ASSOC_RULE_FOLDER, ASSOC_RULE_FOLDER).stream()
|
||||
.map(ChildAssociationRef::getChildRef)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
@@ -1670,7 +1680,10 @@ public class RuleServiceImpl
|
||||
@Experimental
|
||||
public boolean isRuleSetAssociatedWithFolder(final NodeRef ruleSetNodeRef, final NodeRef folderNodeRef)
|
||||
{
|
||||
return isChildOf(ruleSetNodeRef, RuleModel.ASSOC_RULE_FOLDER, folderNodeRef);
|
||||
List<ChildAssociationRef> associations = runtimeNodeService.getParentAssocs(ruleSetNodeRef, ASSOC_RULE_FOLDER, ASSOC_RULE_FOLDER);
|
||||
Set<NodeRef> associatedFolders = associations.stream().map(ChildAssociationRef::getParentRef).collect(Collectors.toSet());
|
||||
Set<NodeRef> supplyingFolders = new HashSet<>(getNodesSupplyingRuleSets(folderNodeRef));
|
||||
return !Sets.intersection(associatedFolders, supplyingFolders).isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -311,7 +311,17 @@ public interface RuleService
|
||||
*/
|
||||
@Auditable(parameters = {"action"})
|
||||
public NodeRef getOwningNodeRef(Action action);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the owning node reference for a rule.
|
||||
*
|
||||
* @param ruleSet The rule set node.
|
||||
* @return the owning node reference
|
||||
*/
|
||||
@Auditable (parameters = { "ruleSet" })
|
||||
@Experimental
|
||||
NodeRef getOwningNodeRef(NodeRef ruleSet);
|
||||
|
||||
/**
|
||||
* Indicates whether the passed rule node reference is linked to another
|
||||
* rule node.
|
||||
@@ -353,7 +363,7 @@ public interface RuleService
|
||||
NodeRef getRuleSetNode(final NodeRef folderNodeRef);
|
||||
|
||||
/**
|
||||
* Check if rule set's associated parent matches folder node.
|
||||
* Check if rule set is associated (owned/linked/inherited) with the given folder node.
|
||||
*
|
||||
* @param ruleSetNodeRef - node reference of a rule set
|
||||
* @param folderNodeRef - node reference of a folder
|
||||
|
@@ -254,6 +254,8 @@ public class RuleServiceImplUnitTest
|
||||
boolean associated = ruleService.isRuleSetAssociatedWithFolder(RULE_SET_NODE, FOLDER_NODE);
|
||||
|
||||
then(runtimeNodeService).should().getParentAssocs(RULE_SET_NODE, ASSOC_RULE_FOLDER, ASSOC_RULE_FOLDER);
|
||||
then(runtimeNodeService).should().hasAspect(FOLDER_NODE, ASPECT_IGNORE_INHERITED_RULES);
|
||||
then(runtimeNodeService).should().getParentAssocs(FOLDER_NODE);
|
||||
then(runtimeNodeService).shouldHaveNoMoreInteractions();
|
||||
then(nodeService).shouldHaveNoInteractions();
|
||||
assertThat(associated).isTrue();
|
||||
@@ -268,6 +270,8 @@ public class RuleServiceImplUnitTest
|
||||
boolean associated = ruleService.isRuleSetAssociatedWithFolder(RULE_SET_NODE, FOLDER_NODE);
|
||||
|
||||
then(runtimeNodeService).should().getParentAssocs(RULE_SET_NODE, ASSOC_RULE_FOLDER, ASSOC_RULE_FOLDER);
|
||||
then(runtimeNodeService).should().hasAspect(FOLDER_NODE, ASPECT_IGNORE_INHERITED_RULES);
|
||||
then(runtimeNodeService).should().getParentAssocs(FOLDER_NODE);
|
||||
then(runtimeNodeService).shouldHaveNoMoreInteractions();
|
||||
then(nodeService).shouldHaveNoInteractions();
|
||||
assertThat(associated).isFalse();
|
||||
@@ -283,11 +287,45 @@ public class RuleServiceImplUnitTest
|
||||
boolean associated = ruleService.isRuleSetAssociatedWithFolder(RULE_SET_NODE, FOLDER_NODE);
|
||||
|
||||
then(runtimeNodeService).should().getParentAssocs(RULE_SET_NODE, ASSOC_RULE_FOLDER, ASSOC_RULE_FOLDER);
|
||||
then(runtimeNodeService).should().hasAspect(FOLDER_NODE, ASPECT_IGNORE_INHERITED_RULES);
|
||||
then(runtimeNodeService).should().getParentAssocs(FOLDER_NODE);
|
||||
then(runtimeNodeService).shouldHaveNoMoreInteractions();
|
||||
then(nodeService).shouldHaveNoInteractions();
|
||||
assertThat(associated).isFalse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that a rule set is associated with the folder in the following case:
|
||||
* <pre>
|
||||
* parent --[link]-> rule set <-[owned]-- owningFolder
|
||||
* +- child
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
public void testIsRuleSetAssociatedWithFolder_inheritedLinkedAssociation()
|
||||
{
|
||||
// The rule is owned by one node.
|
||||
NodeRef owningFolder = new NodeRef("owning://node/");
|
||||
// The rule is linked to by the parent node.
|
||||
NodeRef parent = new NodeRef("parent://node/");
|
||||
List<ChildAssociationRef> ruleAssociations = List.of(createAssociation(owningFolder, RULE_SET_NODE), createAssociation(parent, RULE_SET_NODE));
|
||||
given(runtimeNodeService.getParentAssocs(RULE_SET_NODE, ASSOC_RULE_FOLDER, ASSOC_RULE_FOLDER)).willReturn(ruleAssociations);
|
||||
// The parent and the child both supply rule sets.
|
||||
given(runtimeNodeService.getParentAssocs(FOLDER_NODE)).willReturn(List.of(createAssociation(parent, FOLDER_NODE)));
|
||||
|
||||
// when
|
||||
boolean associated = ruleService.isRuleSetAssociatedWithFolder(RULE_SET_NODE, FOLDER_NODE);
|
||||
|
||||
then(runtimeNodeService).should().getParentAssocs(RULE_SET_NODE, ASSOC_RULE_FOLDER, ASSOC_RULE_FOLDER);
|
||||
then(runtimeNodeService).should().hasAspect(FOLDER_NODE, ASPECT_IGNORE_INHERITED_RULES);
|
||||
then(runtimeNodeService).should().getParentAssocs(FOLDER_NODE);
|
||||
then(runtimeNodeService).should().hasAspect(parent, ASPECT_IGNORE_INHERITED_RULES);
|
||||
then(runtimeNodeService).should().getParentAssocs(parent);
|
||||
then(runtimeNodeService).shouldHaveNoMoreInteractions();
|
||||
then(nodeService).shouldHaveNoInteractions();
|
||||
assertThat(associated).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsRuleAssociatedWithRuleSet()
|
||||
{
|
||||
|
Reference in New Issue
Block a user