Class RuleServiceImpl

java.lang.Object
org.alfresco.repo.rule.RuleServiceImpl
All Implemented Interfaces:
NodeServicePolicies.OnAddAspectPolicy, NodeServicePolicies.OnCreateChildAssociationPolicy, NodeServicePolicies.OnCreateNodePolicy, NodeServicePolicies.OnUpdateNodePolicy, AssociationPolicy, ClassPolicy, Policy, RuntimeRuleService, RuleService

Rule service implementation.

This service automatically binds to the transaction flush hooks. It will therefore participate in any flushes that occur during the transaction as well.

Author:
Roy Wetherall
  • Constructor Details

    • RuleServiceImpl

      public RuleServiceImpl()
  • Method Details

    • setNodeService

      public void setNodeService(NodeService nodeService)
      Set the permission-safe node service
    • setRuntimeNodeService

      public void setRuntimeNodeService(NodeService runtimeNodeService)
      Set the direct node service
    • setCopyService

      public void setCopyService(CopyService copyService)
      Set the service for locating copied nodes' originals
    • setActionService

      public void setActionService(ActionService actionService)
      Set the action service
    • setRuntimeActionService

      public void setRuntimeActionService(RuntimeActionService runtimeActionService)
      Set the runtime action service
    • setDictionaryService

      public void setDictionaryService(DictionaryService dictionaryService)
      Set the dictionary service
    • setPolicyComponent

      public void setPolicyComponent(PolicyComponent policyComponent)
      Set the policy component to listen for various events
    • setPermissionService

      public void setPermissionService(PermissionService permissionService)
      Set the permission service
    • setNodeRulesCache

      public void setNodeRulesCache(SimpleCache<NodeRef,List<Rule>> nodeRulesCache)
      Set the cache to hold node's individual rules. This cache must not be shared across transactions.
      Parameters:
      nodeRulesCache - a cache of raw rules contained on a node
      See Also:
    • setRulesDisabled

      public void setRulesDisabled(boolean rulesDisabled)
      Set the global rules disabled flag
      Parameters:
      rulesDisabled - true to disable allr ules, false otherwise
    • init

      public void init()
      Registers to listen for events of interest. For instance, the creation or deletion of a rule folder will affect the caching of rules.
    • onCreateChildAssociation

      public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean isNewNode)
      Cache invalidation
      Specified by:
      onCreateChildAssociation in interface NodeServicePolicies.OnCreateChildAssociationPolicy
      Parameters:
      childAssocRef - the child association that has been created
      isNewNode - true if the node is new or false if the node is being linked in
    • onUpdateNode

      public void onUpdateNode(NodeRef nodeRef)
      Cache invalidation
      Specified by:
      onUpdateNode in interface NodeServicePolicies.OnUpdateNodePolicy
      Parameters:
      nodeRef - reference to the updated node
    • onCreateNode

      public void onCreateNode(ChildAssociationRef childAssocRef)
      Cache invalidation
      Specified by:
      onCreateNode in interface NodeServicePolicies.OnCreateNodePolicy
      Parameters:
      childAssocRef - the created child association reference
    • onAddAspect

      public void onAddAspect(NodeRef nodeRef, QName aspectTypeQName)
      Cache invalidation
      Specified by:
      onAddAspect in interface NodeServicePolicies.OnAddAspectPolicy
      Parameters:
      nodeRef - the node to which the aspect was added
      aspectTypeQName - the type of the aspect
    • getSavedRuleFolderRef

      protected NodeRef getSavedRuleFolderRef(NodeRef nodeRef)
    • getSavedRuleFolderAssoc

      public ChildAssociationRef getSavedRuleFolderAssoc(NodeRef nodeRef)
      Gets the saved rule folder reference
      Specified by:
      getSavedRuleFolderAssoc in interface RuntimeRuleService
      Parameters:
      nodeRef - the node reference
      Returns:
      the node reference
    • getRuleTypes

      public List<RuleType> getRuleTypes()
      Description copied from interface: RuleService
      Get the rule types currently defined in the repository.
      Specified by:
      getRuleTypes in interface RuleService
      Returns:
      a list of rule types
    • getRuleType

      public RuleType getRuleType(String name)
      Description copied from interface: RuleService
      Gets a rule type by name.
      Specified by:
      getRuleType in interface RuleService
      Parameters:
      name - the name of the rule type
      Returns:
      the rule type, null if not found
    • enableRules

      public void enableRules()
      Description copied from interface: RuleService
      Enable rules for the current thread
      Specified by:
      enableRules in interface RuleService
      See Also:
    • disableRules

      public void disableRules()
      Description copied from interface: RuleService
      Disable rules for the current thread
      Specified by:
      disableRules in interface RuleService
      See Also:
    • isEnabled

      public boolean isEnabled()
      Description copied from interface: RuleService
      Indicates whether rules are currently enabled for the current thread or not
      Specified by:
      isEnabled in interface RuleService
      Returns:
      true if rules are enabled for the current thread, false otherwise
      See Also:
    • rulesEnabled

      public boolean rulesEnabled(NodeRef nodeRef)
      Description copied from interface: RuleService
      Indicates whether the rules for a given node are enabled or not. If the rules are not enabled then they will not be executed.
      Specified by:
      rulesEnabled in interface RuleService
      Parameters:
      nodeRef - the node reference
      Returns:
      true if the rules are enabled, false otherwise
    • disableRules

      public void disableRules(NodeRef nodeRef)
      Description copied from interface: RuleService
      Disables the rules for a given node reference. When the rules are disabled they will not execute.
      Specified by:
      disableRules in interface RuleService
      Parameters:
      nodeRef - the node reference
    • enableRules

      public void enableRules(NodeRef nodeRef)
      Description copied from interface: RuleService
      Enables the rules for a given node reference. When the rules are enabled they will execute as usual. By default all rules are enabled.
      Specified by:
      enableRules in interface RuleService
      Parameters:
      nodeRef - the node reference
    • disableRule

      public void disableRule(Rule rule)
      Description copied from interface: RuleService
      Disables a rule, preventing it from being fired.
      Specified by:
      disableRule in interface RuleService
      Parameters:
      rule - the rule to disable
      See Also:
    • enableRule

      public void enableRule(Rule rule)
      Description copied from interface: RuleService
      Enables a rule previously disabled.
      Specified by:
      enableRule in interface RuleService
      Parameters:
      rule - the rule to enable
      See Also:
    • disableRuleType

      public void disableRuleType(String ruleType)
      Description copied from interface: RuleService
      Disables the rules of a given type.
      Specified by:
      disableRuleType in interface RuleService
      Parameters:
      ruleType - rule type
    • enableRuleType

      public void enableRuleType(String ruleType)
      Description copied from interface: RuleService
      Enables rules of a given type.
      Specified by:
      enableRuleType in interface RuleService
      Parameters:
      ruleType - rule type
    • isRuleTypeEnabled

      public boolean isRuleTypeEnabled(String ruleType)
      Description copied from interface: RuleService
      Indicates whether the rule is enabled or not
      Specified by:
      isRuleTypeEnabled in interface RuleService
      Parameters:
      ruleType - rule type
      Returns:
      boolean true if enabled false otherwise
    • hasRules

      public boolean hasRules(NodeRef nodeRef)
      Description copied from interface: RuleService
      Indicates whether the node in question has any rules associated with it.
      Specified by:
      hasRules in interface RuleService
      Parameters:
      nodeRef - the node reference
      Returns:
      true if the node has rules associated, false otherwise
    • hasNonInheritedRules

      public boolean hasNonInheritedRules(NodeRef nodeRef)
      Description copied from interface: RuleService
      Indicates whether the node in question has any non-inherited rules associated with it.
      Specified by:
      hasNonInheritedRules in interface RuleService
      Parameters:
      nodeRef - the node reference
      Returns:
      true if the node has rules associated, false otherwise
    • getRules

      public List<Rule> getRules(NodeRef nodeRef)
      Description copied from interface: RuleService
      Get all the rules associated with an actionable node, including those inherited from parents.

      An exception is raised if the actionable aspect is not present on the passed node.

      Specified by:
      getRules in interface RuleService
      Parameters:
      nodeRef - the node reference
      Returns:
      a list of the rules associated with the node
    • getRules

      public List<Rule> getRules(NodeRef nodeRef, boolean includeInherited)
      Description copied from interface: RuleService
      Get the rules associated with an actionable node.

      Optionally this list includes rules inherited from its parents.

      An exception is raised if the actionable aspect is not present on the passed node.

      Specified by:
      getRules in interface RuleService
      Parameters:
      nodeRef - the node reference
      includeInherited - indicates whether the inherited rules should be included in the result list or not
      Returns:
      a list of the rules associated with the node
    • getRules

      public List<Rule> getRules(NodeRef nodeRef, boolean includeInherited, String ruleTypeName)
      Description copied from interface: RuleService
      Get the rules associated with an actionable node that are of a specific rule type.
      Specified by:
      getRules in interface RuleService
      Parameters:
      nodeRef - the node reference
      includeInherited - indicates whether the inherited rules should be included in the result list or not
      ruleTypeName - the name of the rule type, if null is passed all rule types are returned
      Returns:
      a list of the rules associated with the node
    • countRules

      public int countRules(NodeRef nodeRef)
      Description copied from interface: RuleService
      Count the number of rules associated with an actionable node.
      Specified by:
      countRules in interface RuleService
      Parameters:
      nodeRef - the node reference
      Returns:
      a list of the rules associated with the node
    • getNodesSupplyingRuleSets

      @Experimental public List<NodeRef> getNodesSupplyingRuleSets(NodeRef nodeRef)
      Traverse the folder hierarchy find all the folder nodes that could supply rules by inheritance.
      Specified by:
      getNodesSupplyingRuleSets in interface RuleService
      Parameters:
      nodeRef - The starting node ref.
      Returns:
      A list of node refs, starting with the first parent of the first parent of ... and ending with the object generated by the given node ref.
    • getFoldersInheritingRuleSet

      @Experimental public List<NodeRef> getFoldersInheritingRuleSet(NodeRef ruleSet, int maxFoldersToReturn)
      Get a list of folders inheriting the specified rule set.
      Specified by:
      getFoldersInheritingRuleSet in interface RuleService
      Parameters:
      ruleSet - The rule set node.
      maxFoldersToReturn - A limit on the number of folders to return (since otherwise this could traverse a very large proportion of the repository).
      Returns:
      The list of the inheriting folders.
    • getFoldersLinkingToRuleSet

      @Experimental public List<NodeRef> getFoldersLinkingToRuleSet(NodeRef ruleSet, int maxFoldersToReturn)
      Get a list of folders linking to the specified rule set.
      Specified by:
      getFoldersLinkingToRuleSet in interface RuleService
      Parameters:
      ruleSet - The rule set node.
      maxFoldersToReturn - A limit on the number of folders to return.
      Returns:
      The list linking folders.
    • getRule

      public Rule getRule(NodeRef ruleNodeRef)
      Create the rule object from the rule node reference
      Specified by:
      getRule in interface RuleService
      Parameters:
      ruleNodeRef - the rule node reference
      Returns:
      the rule
    • saveRule

      public Rule saveRule(NodeRef nodeRef, Rule rule)
      Description copied from interface: RuleService
      Saves the details of the rule to the specified node reference.

      If the rule is already associated with the node, the details are updated with those specified.

      Specified by:
      saveRule in interface RuleService
      Parameters:
      nodeRef - NodeRef
      rule - Rule
    • saveRule

      public void saveRule(NodeRef nodeRef, Rule rule, int index)
      Specified by:
      saveRule in interface RuleService
      Parameters:
      nodeRef - NodeRef
      rule - Rule
      index - int
    • setRulePosition

      public void setRulePosition(NodeRef nodeRef, NodeRef ruleNodeRef, int index)
      Specified by:
      setRulePosition in interface RuleService
      Parameters:
      nodeRef - NodeRef
      ruleNodeRef - NodeRef
      index - int
    • setRulePosition

      public void setRulePosition(NodeRef nodeRef, Rule rule, int index)
      Specified by:
      setRulePosition in interface RuleService
      Parameters:
      nodeRef - NodeRef
      rule - Rule
      index - int
    • removeRule

      public void removeRule(NodeRef nodeRef, Rule rule)
      Description copied from interface: RuleService
      Removes a rule from the given rule actionable node
      Specified by:
      removeRule in interface RuleService
      Parameters:
      nodeRef - the actionable node reference
    • removeAllRules

      public void removeAllRules(NodeRef nodeRef)
      Description copied from interface: RuleService
      Removes all the rules associated with an actionable node
      Specified by:
      removeAllRules in interface RuleService
      Parameters:
      nodeRef - the actionable node reference
    • addRulePendingExecution

      public void addRulePendingExecution(NodeRef actionableNodeRef, NodeRef actionedUponNodeRef, Rule rule)
      Description copied from interface: RuntimeRuleService
      Add a rule to the pending execution list
      Specified by:
      addRulePendingExecution in interface RuntimeRuleService
      Parameters:
      actionableNodeRef - actionable node reference
      actionedUponNodeRef - actioned upon node reference
      rule - rule
    • removeRulePendingExecution

      public void removeRulePendingExecution(NodeRef actionedUponNodeRef)
      Description copied from interface: RuntimeRuleService
      Remove all pending rules that are actioning upon the given node reference
      Specified by:
      removeRulePendingExecution in interface RuntimeRuleService
      Parameters:
      actionedUponNodeRef - actioned upon node reference
    • addRulePendingExecution

      public void addRulePendingExecution(NodeRef actionableNodeRef, NodeRef actionedUponNodeRef, Rule rule, boolean executeAtEnd)
      Description copied from interface: RuntimeRuleService
      Add a rule to the pending execution list
      Specified by:
      addRulePendingExecution in interface RuntimeRuleService
      Parameters:
      actionableNodeRef - actionable node reference
      actionedUponNodeRef - actioned upon node reference
      rule - rule
      executeAtEnd - true if execute rule at the end of the transaction, false otherwise
    • executePendingRules

      public void executePendingRules()
      Description copied from interface: RuntimeRuleService
      Execute all pending rules
      Specified by:
      executePendingRules in interface RuntimeRuleService
    • executeRule

      public void executeRule(Rule rule, NodeRef actionedUponNodeRef, Set<RuleServiceImpl.ExecutedRuleData> executedRules)
      Description copied from interface: RuntimeRuleService
      Execute a rule
      Specified by:
      executeRule in interface RuntimeRuleService
      Parameters:
      rule - rule
      actionedUponNodeRef - actioned upon node reference
      executedRules - already executed rules
    • registerRuleType

      public void registerRuleType(RuleType ruleType)
      Register the rule type
      Specified by:
      registerRuleType in interface RuntimeRuleService
      Parameters:
      ruleType - the rule type adapter
    • getOwningNodeRef

      public NodeRef getOwningNodeRef(Rule rule)
      Description copied from interface: RuleService
      Returns the owning node reference for a rule.
      Specified by:
      getOwningNodeRef in interface RuleService
      Parameters:
      rule - the rule
      Returns:
      the owning node reference
    • getOwningNodeRef

      public NodeRef getOwningNodeRef(NodeRef ruleSet)
      Description copied from interface: RuleService
      Returns the owning node reference for a rule.
      Specified by:
      getOwningNodeRef in interface RuleService
      Parameters:
      ruleSet - The rule set node.
      Returns:
      the owning node reference
    • getOwningNodeRef

      public NodeRef getOwningNodeRef(Action action)
      Description copied from interface: RuleService
      Returns the owning node reference for an action. Returns null for an unsaved action or one that is not parented by a rule. NOTE: this method is temporary and will be removed in future versions. It should only be used with good reason.
      Specified by:
      getOwningNodeRef in interface RuleService
      Parameters:
      action - the action
      Returns:
      the owning node reference
    • isLinkedToRuleNode

      public boolean isLinkedToRuleNode(NodeRef nodeRef)
      Description copied from interface: RuleService
      Indicates whether the passed rule node reference is linked to another rule node.
      Specified by:
      isLinkedToRuleNode in interface RuleService
      Parameters:
      nodeRef - rule node reference
      Returns:
      boolean true if linked, false otherwise
    • getLinkedToRuleNode

      public NodeRef getLinkedToRuleNode(NodeRef nodeRef)
      Description copied from interface: RuleService
      Get the node reference to the rule node which the rule node links to. Returns null if rules are not linked.
      Specified by:
      getLinkedToRuleNode in interface RuleService
      Parameters:
      nodeRef - node reference of a rule node
      Returns:
      NodeRef reference to the
    • getLinkedFromRuleNodes

      public List<NodeRef> getLinkedFromRuleNodes(NodeRef nodeRef)
      Description copied from interface: RuleService
      Get a list of the all the rule nodes that link to the passed rule node. Returns an empty list if none link.
      Specified by:
      getLinkedFromRuleNodes in interface RuleService
      Parameters:
      nodeRef - node reference of a rule node
      Returns:
      list of rule nodes that link to this passed rule node, empty if none
    • getRuleSetNode

      @Experimental public NodeRef getRuleSetNode(NodeRef folderNodeRef)
      Description copied from interface: RuleService
      Get rule set node associated with folder
      Specified by:
      getRuleSetNode in interface RuleService
      Parameters:
      folderNodeRef - - folder node reference
      Returns:
      node reference of a rule set
    • isRuleSetAssociatedWithFolder

      @Experimental public boolean isRuleSetAssociatedWithFolder(NodeRef ruleSetNodeRef, NodeRef folderNodeRef)
      Description copied from interface: RuleService
      Check if rule set is associated (owned/linked/inherited) with the given folder node.
      Specified by:
      isRuleSetAssociatedWithFolder in interface RuleService
      Parameters:
      ruleSetNodeRef - - node reference of a rule set
      folderNodeRef - - node reference of a folder
      Returns:
      true if rule set is associated with folder
    • isRuleAssociatedWithRuleSet

      @Experimental public boolean isRuleAssociatedWithRuleSet(NodeRef ruleNodeRef, NodeRef ruleSetNodeRef)
      Description copied from interface: RuleService
      Check if rule's associated parent matches rule set node.
      Specified by:
      isRuleAssociatedWithRuleSet in interface RuleService
      Parameters:
      ruleNodeRef - - node reference of a rule
      ruleSetNodeRef - - node reference of a rule set
      Returns:
      true if rule is associated with rule set
    • isRuleSetShared

      @Experimental public boolean isRuleSetShared(NodeRef ruleSetNodeRef)
      Description copied from interface: RuleService
      Check if other folders are linked to rule set.
      Specified by:
      isRuleSetShared in interface RuleService
      Parameters:
      ruleSetNodeRef - - node reference of a rule set
      Returns:
      true if others folders are linked to rule set