1 17 package org.alfresco.repo.rule; 18 19 import java.util.List ; 20 21 import org.alfresco.i18n.I18NUtil; 22 import org.alfresco.repo.action.CommonResourceAbstractBase; 23 import org.alfresco.repo.rule.ruletrigger.RuleTrigger; 24 import org.alfresco.service.cmr.action.ActionService; 25 import org.alfresco.service.cmr.repository.NodeRef; 26 import org.alfresco.service.cmr.rule.Rule; 27 import org.alfresco.service.cmr.rule.RuleService; 28 import org.alfresco.service.cmr.rule.RuleType; 29 import org.apache.commons.logging.Log; 30 import org.apache.commons.logging.LogFactory; 31 32 37 public class RuleTypeImpl extends CommonResourceAbstractBase implements RuleType 38 { 39 42 private static Log logger = LogFactory.getLog(RuleTypeImpl.class); 43 44 47 private ActionService actionService; 48 49 52 private RuleService ruleService; 53 54 59 public RuleTypeImpl(List <RuleTrigger> ruleTriggers) 60 { 61 if (ruleTriggers != null) 62 { 63 for (RuleTrigger trigger : ruleTriggers) 64 { 65 trigger.registerRuleType(this); 66 } 67 } 68 } 69 70 75 public void setActionService(ActionService actionService) 76 { 77 this.actionService = actionService; 78 } 79 80 85 public void setRuleService(RuleService ruleService) 86 { 87 this.ruleService = ruleService; 88 } 89 90 93 public void init() 94 { 95 ((RuntimeRuleService)this.ruleService).registerRuleType(this); 96 } 97 98 101 public String getName() 102 { 103 return this.name; 104 } 105 106 109 public String getDisplayLabel() 110 { 111 return I18NUtil.getMessage(this.name + "." + "display-label"); 112 } 113 114 117 public void triggerRuleType(NodeRef nodeRef, NodeRef actionedUponNodeRef) 118 { 119 if (this.ruleService.hasRules(nodeRef) == true) 120 { 121 List <Rule> rules = this.ruleService.getRules( 122 nodeRef, 123 true, 124 this.name); 125 126 for (Rule rule : rules) 127 { 128 if (logger.isDebugEnabled() == true) 129 { 130 logger.debug("Triggering rule " + rule.getId()); 131 } 132 133 if (rule.getExecuteAsychronously() == true) 134 { 135 this.actionService.executeAction(rule, actionedUponNodeRef); 137 } 138 else 139 { 140 ((RuntimeRuleService)this.ruleService).addRulePendingExecution(nodeRef, actionedUponNodeRef, rule); 142 } 143 } 144 } 145 else 146 { 147 if (logger.isDebugEnabled() == true) 148 { 149 logger.debug("This node has no rules to trigger."); 150 } 151 } 152 } 153 154 157 public void setBeanName(String name) 158 { 159 this.name = name; 160 } 161 } 162 | Popular Tags |