Package org.alfresco.repo.rule
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
public class RuleServiceImpl extends java.lang.Object implements RuleService, RuntimeRuleService, NodeServicePolicies.OnCreateChildAssociationPolicy, NodeServicePolicies.OnCreateNodePolicy, NodeServicePolicies.OnUpdateNodePolicy, NodeServicePolicies.OnAddAspectPolicy
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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classRuleServiceImpl.ExecutedRuleDataHelper class to contain the information about a rule that is executed-
Nested classes/interfaces inherited from interface org.alfresco.repo.policy.Policy
Policy.Arg
-
-
Field Summary
-
Fields inherited from interface org.alfresco.repo.node.NodeServicePolicies.OnAddAspectPolicy
QNAME
-
Fields inherited from interface org.alfresco.repo.node.NodeServicePolicies.OnCreateChildAssociationPolicy
QNAME
-
Fields inherited from interface org.alfresco.repo.node.NodeServicePolicies.OnCreateNodePolicy
QNAME
-
Fields inherited from interface org.alfresco.repo.node.NodeServicePolicies.OnUpdateNodePolicy
QNAME
-
-
Constructor Summary
Constructors Constructor Description RuleServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddRulePendingExecution(org.alfresco.service.cmr.repository.NodeRef actionableNodeRef, org.alfresco.service.cmr.repository.NodeRef actionedUponNodeRef, Rule rule)Add a rule to the pending execution listvoidaddRulePendingExecution(org.alfresco.service.cmr.repository.NodeRef actionableNodeRef, org.alfresco.service.cmr.repository.NodeRef actionedUponNodeRef, Rule rule, boolean executeAtEnd)Add a rule to the pending execution listintcountRules(org.alfresco.service.cmr.repository.NodeRef nodeRef)Count the number of rules associated with an actionable node.voiddisableRule(Rule rule)Disables a rule, preventing it from being fired.voiddisableRules()Disable rules for the current threadvoiddisableRules(org.alfresco.service.cmr.repository.NodeRef nodeRef)Disables the rules for a given node reference.voiddisableRuleType(java.lang.String ruleType)Disables the rules of a given type.voidenableRule(Rule rule)Enables a rule previously disabled.voidenableRules()Enable rules for the current threadvoidenableRules(org.alfresco.service.cmr.repository.NodeRef nodeRef)Enables the rules for a given node reference.voidenableRuleType(java.lang.String ruleType)Enables rules of a given type.voidexecutePendingRules()Execute all pending rulesvoidexecuteRule(Rule rule, org.alfresco.service.cmr.repository.NodeRef actionedUponNodeRef, java.util.Set<RuleServiceImpl.ExecutedRuleData> executedRules)Execute a rulejava.util.List<org.alfresco.service.cmr.repository.NodeRef>getLinkedFromRuleNodes(org.alfresco.service.cmr.repository.NodeRef nodeRef)Get a list of the all the rule nodes that link to the passed rule node.org.alfresco.service.cmr.repository.NodeRefgetLinkedToRuleNode(org.alfresco.service.cmr.repository.NodeRef nodeRef)Get the node reference to the rule node which the rule node links to.org.alfresco.service.cmr.repository.NodeRefgetOwningNodeRef(Action action)Returns the owning node reference for an action.org.alfresco.service.cmr.repository.NodeRefgetOwningNodeRef(Rule rule)Returns the owning node reference for a rule.RulegetRule(org.alfresco.service.cmr.repository.NodeRef ruleNodeRef)Create the rule object from the rule node referencejava.util.List<Rule>getRules(org.alfresco.service.cmr.repository.NodeRef nodeRef)Get all the rules associated with an actionable node, including those inherited from parents.java.util.List<Rule>getRules(org.alfresco.service.cmr.repository.NodeRef nodeRef, boolean includeInherited)Get the rules associated with an actionable node.java.util.List<Rule>getRules(org.alfresco.service.cmr.repository.NodeRef nodeRef, boolean includeInherited, java.lang.String ruleTypeName)Get the rules associated with an actionable node that are of a specific rule type.RuleTypegetRuleType(java.lang.String name)Gets a rule type by name.java.util.List<RuleType>getRuleTypes()Get the rule types currently defined in the repository.org.alfresco.service.cmr.repository.ChildAssociationRefgetSavedRuleFolderAssoc(org.alfresco.service.cmr.repository.NodeRef nodeRef)Gets the saved rule folder referenceprotected org.alfresco.service.cmr.repository.NodeRefgetSavedRuleFolderRef(org.alfresco.service.cmr.repository.NodeRef nodeRef)booleanhasRules(org.alfresco.service.cmr.repository.NodeRef nodeRef)Indicates whether the node in question has any rules associated with it.voidinit()Registers to listen for events of interest.booleanisEnabled()Indicates whether rules are currently enabled for the current thread or notbooleanisLinkedToRuleNode(org.alfresco.service.cmr.repository.NodeRef nodeRef)Indicates whether the passed rule node reference is linked to another rule node.booleanisRuleTypeEnabled(java.lang.String ruleType)Indicates whether the rule is enabled or notvoidonAddAspect(org.alfresco.service.cmr.repository.NodeRef nodeRef, org.alfresco.service.namespace.QName aspectTypeQName)Cache invalidationvoidonCreateChildAssociation(org.alfresco.service.cmr.repository.ChildAssociationRef childAssocRef, boolean isNewNode)Cache invalidationvoidonCreateNode(org.alfresco.service.cmr.repository.ChildAssociationRef childAssocRef)Cache invalidationvoidonUpdateNode(org.alfresco.service.cmr.repository.NodeRef nodeRef)Cache invalidationvoidregisterRuleType(RuleType ruleType)Register the rule typevoidremoveAllRules(org.alfresco.service.cmr.repository.NodeRef nodeRef)Removes all the rules associated with an actionable nodevoidremoveRule(org.alfresco.service.cmr.repository.NodeRef nodeRef, Rule rule)Removes a rule from the given rule actionable nodevoidremoveRulePendingExecution(org.alfresco.service.cmr.repository.NodeRef actionedUponNodeRef)Remove all pending rules that are actioning upon the given node referencebooleanrulesEnabled(org.alfresco.service.cmr.repository.NodeRef nodeRef)Indicates whether the rules for a given node are enabled or not.voidsaveRule(org.alfresco.service.cmr.repository.NodeRef nodeRef, Rule rule)Saves the details of the rule to the specified node reference.voidsaveRule(org.alfresco.service.cmr.repository.NodeRef nodeRef, Rule rule, int index)voidsetActionService(ActionService actionService)Set the action servicevoidsetCopyService(CopyService copyService)Set the service for locating copied nodes' originalsvoidsetDictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService dictionaryService)Set the dictionary servicevoidsetNodeRulesCache(org.alfresco.repo.cache.SimpleCache<org.alfresco.service.cmr.repository.NodeRef,java.util.List<Rule>> nodeRulesCache)Set the cache to hold node's individual rules.voidsetNodeService(org.alfresco.service.cmr.repository.NodeService nodeService)Set the permission-safe node servicevoidsetPermissionService(org.alfresco.service.cmr.security.PermissionService permissionService)Set the permission servicevoidsetPolicyComponent(PolicyComponent policyComponent)Set the policy component to listen for various eventsvoidsetRulePosition(org.alfresco.service.cmr.repository.NodeRef nodeRef, org.alfresco.service.cmr.repository.NodeRef ruleNodeRef, int index)voidsetRulePosition(org.alfresco.service.cmr.repository.NodeRef nodeRef, Rule rule, int index)voidsetRulesDisabled(boolean rulesDisabled)Set the global rules disabled flagvoidsetRuntimeActionService(RuntimeActionService runtimeActionService)Set the runtime action servicevoidsetRuntimeNodeService(org.alfresco.service.cmr.repository.NodeService runtimeNodeService)Set the direct node service
-
-
-
Method Detail
-
setNodeService
public void setNodeService(org.alfresco.service.cmr.repository.NodeService nodeService)
Set the permission-safe node service
-
setRuntimeNodeService
public void setRuntimeNodeService(org.alfresco.service.cmr.repository.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(org.alfresco.service.cmr.dictionary.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(org.alfresco.service.cmr.security.PermissionService permissionService)
Set the permission service
-
setNodeRulesCache
public void setNodeRulesCache(org.alfresco.repo.cache.SimpleCache<org.alfresco.service.cmr.repository.NodeRef,java.util.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:
NullCache
-
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(org.alfresco.service.cmr.repository.ChildAssociationRef childAssocRef, boolean isNewNode)Cache invalidation- Specified by:
onCreateChildAssociationin interfaceNodeServicePolicies.OnCreateChildAssociationPolicy- Parameters:
childAssocRef- the child association that has been createdisNewNode- true if the node is new or false if the node is being linked in
-
onUpdateNode
public void onUpdateNode(org.alfresco.service.cmr.repository.NodeRef nodeRef)
Cache invalidation- Specified by:
onUpdateNodein interfaceNodeServicePolicies.OnUpdateNodePolicy- Parameters:
nodeRef- reference to the updated node
-
onCreateNode
public void onCreateNode(org.alfresco.service.cmr.repository.ChildAssociationRef childAssocRef)
Cache invalidation- Specified by:
onCreateNodein interfaceNodeServicePolicies.OnCreateNodePolicy- Parameters:
childAssocRef- the created child association reference
-
onAddAspect
public void onAddAspect(org.alfresco.service.cmr.repository.NodeRef nodeRef, org.alfresco.service.namespace.QName aspectTypeQName)Cache invalidation- Specified by:
onAddAspectin interfaceNodeServicePolicies.OnAddAspectPolicy- Parameters:
nodeRef- the node to which the aspect was addedaspectTypeQName- the type of the aspect
-
getSavedRuleFolderRef
protected org.alfresco.service.cmr.repository.NodeRef getSavedRuleFolderRef(org.alfresco.service.cmr.repository.NodeRef nodeRef)
-
getSavedRuleFolderAssoc
public org.alfresco.service.cmr.repository.ChildAssociationRef getSavedRuleFolderAssoc(org.alfresco.service.cmr.repository.NodeRef nodeRef)
Gets the saved rule folder reference- Specified by:
getSavedRuleFolderAssocin interfaceRuntimeRuleService- Parameters:
nodeRef- the node reference- Returns:
- the node reference
-
getRuleTypes
public java.util.List<RuleType> getRuleTypes()
Description copied from interface:RuleServiceGet the rule types currently defined in the repository.- Specified by:
getRuleTypesin interfaceRuleService- Returns:
- a list of rule types
-
getRuleType
public RuleType getRuleType(java.lang.String name)
Description copied from interface:RuleServiceGets a rule type by name.- Specified by:
getRuleTypein interfaceRuleService- Parameters:
name- the name of the rule type- Returns:
- the rule type, null if not found
-
enableRules
public void enableRules()
Description copied from interface:RuleServiceEnable rules for the current thread- Specified by:
enableRulesin interfaceRuleService- See Also:
RuleService.isEnabled(),RuleService.disableRules()
-
disableRules
public void disableRules()
Description copied from interface:RuleServiceDisable rules for the current thread- Specified by:
disableRulesin interfaceRuleService- See Also:
RuleService.enableRules(),RuleService.isEnabled()
-
isEnabled
public boolean isEnabled()
Description copied from interface:RuleServiceIndicates whether rules are currently enabled for the current thread or not- Specified by:
isEnabledin interfaceRuleService- Returns:
- true if rules are enabled for the current thread, false otherwise
- See Also:
RuleService.enableRules(),RuleService.disableRules()
-
rulesEnabled
public boolean rulesEnabled(org.alfresco.service.cmr.repository.NodeRef nodeRef)
Description copied from interface:RuleServiceIndicates 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:
rulesEnabledin interfaceRuleService- Parameters:
nodeRef- the node reference- Returns:
- true if the rules are enabled, false otherwise
-
disableRules
public void disableRules(org.alfresco.service.cmr.repository.NodeRef nodeRef)
Description copied from interface:RuleServiceDisables the rules for a given node reference. When the rules are disabled they will not execute.- Specified by:
disableRulesin interfaceRuleService- Parameters:
nodeRef- the node reference
-
enableRules
public void enableRules(org.alfresco.service.cmr.repository.NodeRef nodeRef)
Description copied from interface:RuleServiceEnables 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:
enableRulesin interfaceRuleService- Parameters:
nodeRef- the node reference
-
disableRule
public void disableRule(Rule rule)
Description copied from interface:RuleServiceDisables a rule, preventing it from being fired.- Specified by:
disableRulein interfaceRuleService- Parameters:
rule- the rule to disable- See Also:
RuleService.enableRule(Rule)
-
enableRule
public void enableRule(Rule rule)
Description copied from interface:RuleServiceEnables a rule previously disabled.- Specified by:
enableRulein interfaceRuleService- Parameters:
rule- the rule to enable- See Also:
RuleService.disableRule(Rule)
-
disableRuleType
public void disableRuleType(java.lang.String ruleType)
Description copied from interface:RuleServiceDisables the rules of a given type.- Specified by:
disableRuleTypein interfaceRuleService- Parameters:
ruleType- rule type
-
enableRuleType
public void enableRuleType(java.lang.String ruleType)
Description copied from interface:RuleServiceEnables rules of a given type.- Specified by:
enableRuleTypein interfaceRuleService- Parameters:
ruleType- rule type
-
isRuleTypeEnabled
public boolean isRuleTypeEnabled(java.lang.String ruleType)
Description copied from interface:RuleServiceIndicates whether the rule is enabled or not- Specified by:
isRuleTypeEnabledin interfaceRuleService- Parameters:
ruleType- rule type- Returns:
- boolean true if enabled false otherwise
-
hasRules
public boolean hasRules(org.alfresco.service.cmr.repository.NodeRef nodeRef)
Description copied from interface:RuleServiceIndicates whether the node in question has any rules associated with it.- Specified by:
hasRulesin interfaceRuleService- Parameters:
nodeRef- the node reference- Returns:
- true if the node has rules associated, false otherwise
-
getRules
public java.util.List<Rule> getRules(org.alfresco.service.cmr.repository.NodeRef nodeRef)
Description copied from interface:RuleServiceGet 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:
getRulesin interfaceRuleService- Parameters:
nodeRef- the node reference- Returns:
- a list of the rules associated with the node
-
getRules
public java.util.List<Rule> getRules(org.alfresco.service.cmr.repository.NodeRef nodeRef, boolean includeInherited)
Description copied from interface:RuleServiceGet 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:
getRulesin interfaceRuleService- Parameters:
nodeRef- the node referenceincludeInherited- 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 java.util.List<Rule> getRules(org.alfresco.service.cmr.repository.NodeRef nodeRef, boolean includeInherited, java.lang.String ruleTypeName)
Description copied from interface:RuleServiceGet the rules associated with an actionable node that are of a specific rule type.- Specified by:
getRulesin interfaceRuleService- Parameters:
nodeRef- the node referenceincludeInherited- indicates whether the inherited rules should be included in the result list or notruleTypeName- 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(org.alfresco.service.cmr.repository.NodeRef nodeRef)
Description copied from interface:RuleServiceCount the number of rules associated with an actionable node.- Specified by:
countRulesin interfaceRuleService- Parameters:
nodeRef- the node reference- Returns:
- a list of the rules associated with the node
-
getRule
public Rule getRule(org.alfresco.service.cmr.repository.NodeRef ruleNodeRef)
Create the rule object from the rule node reference- Specified by:
getRulein interfaceRuleService- Parameters:
ruleNodeRef- the rule node reference- Returns:
- the rule
-
saveRule
public void saveRule(org.alfresco.service.cmr.repository.NodeRef nodeRef, Rule rule)Description copied from interface:RuleServiceSaves 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:
saveRulein interfaceRuleService- Parameters:
nodeRef- NodeRefrule- Rule
-
saveRule
public void saveRule(org.alfresco.service.cmr.repository.NodeRef nodeRef, Rule rule, int index)- Specified by:
saveRulein interfaceRuleService- Parameters:
nodeRef- NodeRefrule- Ruleindex- int
-
setRulePosition
public void setRulePosition(org.alfresco.service.cmr.repository.NodeRef nodeRef, org.alfresco.service.cmr.repository.NodeRef ruleNodeRef, int index)- Specified by:
setRulePositionin interfaceRuleService- Parameters:
nodeRef- NodeRefruleNodeRef- NodeRefindex- int
-
setRulePosition
public void setRulePosition(org.alfresco.service.cmr.repository.NodeRef nodeRef, Rule rule, int index)- Specified by:
setRulePositionin interfaceRuleService- Parameters:
nodeRef- NodeRefrule- Ruleindex- int
-
removeRule
public void removeRule(org.alfresco.service.cmr.repository.NodeRef nodeRef, Rule rule)Description copied from interface:RuleServiceRemoves a rule from the given rule actionable node- Specified by:
removeRulein interfaceRuleService- Parameters:
nodeRef- the actionable node reference
-
removeAllRules
public void removeAllRules(org.alfresco.service.cmr.repository.NodeRef nodeRef)
Description copied from interface:RuleServiceRemoves all the rules associated with an actionable node- Specified by:
removeAllRulesin interfaceRuleService- Parameters:
nodeRef- the actionable node reference
-
addRulePendingExecution
public void addRulePendingExecution(org.alfresco.service.cmr.repository.NodeRef actionableNodeRef, org.alfresco.service.cmr.repository.NodeRef actionedUponNodeRef, Rule rule)Description copied from interface:RuntimeRuleServiceAdd a rule to the pending execution list- Specified by:
addRulePendingExecutionin interfaceRuntimeRuleService- Parameters:
actionableNodeRef- actionable node referenceactionedUponNodeRef- actioned upon node referencerule- rule
-
removeRulePendingExecution
public void removeRulePendingExecution(org.alfresco.service.cmr.repository.NodeRef actionedUponNodeRef)
Description copied from interface:RuntimeRuleServiceRemove all pending rules that are actioning upon the given node reference- Specified by:
removeRulePendingExecutionin interfaceRuntimeRuleService- Parameters:
actionedUponNodeRef- actioned upon node reference
-
addRulePendingExecution
public void addRulePendingExecution(org.alfresco.service.cmr.repository.NodeRef actionableNodeRef, org.alfresco.service.cmr.repository.NodeRef actionedUponNodeRef, Rule rule, boolean executeAtEnd)Description copied from interface:RuntimeRuleServiceAdd a rule to the pending execution list- Specified by:
addRulePendingExecutionin interfaceRuntimeRuleService- Parameters:
actionableNodeRef- actionable node referenceactionedUponNodeRef- actioned upon node referencerule- ruleexecuteAtEnd- true if execute rule at the end of the transaction, false otherwise
-
executePendingRules
public void executePendingRules()
Description copied from interface:RuntimeRuleServiceExecute all pending rules- Specified by:
executePendingRulesin interfaceRuntimeRuleService
-
executeRule
public void executeRule(Rule rule, org.alfresco.service.cmr.repository.NodeRef actionedUponNodeRef, java.util.Set<RuleServiceImpl.ExecutedRuleData> executedRules)
Description copied from interface:RuntimeRuleServiceExecute a rule- Specified by:
executeRulein interfaceRuntimeRuleService- Parameters:
rule- ruleactionedUponNodeRef- actioned upon node referenceexecutedRules- already executed rules
-
registerRuleType
public void registerRuleType(RuleType ruleType)
Register the rule type- Specified by:
registerRuleTypein interfaceRuntimeRuleService- Parameters:
ruleType- the rule type adapter
-
getOwningNodeRef
public org.alfresco.service.cmr.repository.NodeRef getOwningNodeRef(Rule rule)
Description copied from interface:RuleServiceReturns the owning node reference for a rule.- Specified by:
getOwningNodeRefin interfaceRuleService- Parameters:
rule- the rule- Returns:
- the owning node reference
-
getOwningNodeRef
public org.alfresco.service.cmr.repository.NodeRef getOwningNodeRef(Action action)
Description copied from interface:RuleServiceReturns 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:
getOwningNodeRefin interfaceRuleService- Parameters:
action- the action- Returns:
- the owning node reference
-
isLinkedToRuleNode
public boolean isLinkedToRuleNode(org.alfresco.service.cmr.repository.NodeRef nodeRef)
Description copied from interface:RuleServiceIndicates whether the passed rule node reference is linked to another rule node.- Specified by:
isLinkedToRuleNodein interfaceRuleService- Parameters:
nodeRef- rule node reference- Returns:
- boolean true if linked, false otherwise
-
getLinkedToRuleNode
public org.alfresco.service.cmr.repository.NodeRef getLinkedToRuleNode(org.alfresco.service.cmr.repository.NodeRef nodeRef)
Description copied from interface:RuleServiceGet the node reference to the rule node which the rule node links to. Returns null if rules are not linked.- Specified by:
getLinkedToRuleNodein interfaceRuleService- Parameters:
nodeRef- node reference of a rule node- Returns:
- NodeRef reference to the
-
getLinkedFromRuleNodes
public java.util.List<org.alfresco.service.cmr.repository.NodeRef> getLinkedFromRuleNodes(org.alfresco.service.cmr.repository.NodeRef nodeRef)
Description copied from interface:RuleServiceGet a list of the all the rule nodes that link to the passed rule node. Returns an empty list if none link.- Specified by:
getLinkedFromRuleNodesin interfaceRuleService- Parameters:
nodeRef- node reference of a rule node- Returns:
- list of rule nodes that link to this passed rule node, empty if none
-
-