1 17 package org.alfresco.repo.rule.ruletrigger; 18 19 import java.util.List ; 20 21 import org.alfresco.repo.policy.JavaBehaviour; 22 import org.alfresco.service.cmr.repository.ChildAssociationRef; 23 import org.alfresco.service.cmr.repository.NodeRef; 24 import org.alfresco.service.cmr.rule.RuleServiceException; 25 import org.alfresco.service.namespace.NamespaceService; 26 import org.alfresco.service.namespace.QName; 27 28 public class SingleNodeRefPolicyRuleTrigger extends RuleTriggerAbstractBase 29 { 30 private static final String ERR_POLICY_NAME_NOT_SET = "Unable to register rule trigger since policy name has not been set."; 31 32 private String policyNamespace = NamespaceService.ALFRESCO_URI; 33 34 private String policyName; 35 36 private boolean triggerParentRules = true; 37 38 public void setPolicyNamespace(String policyNamespace) 39 { 40 this.policyNamespace = policyNamespace; 41 } 42 43 public void setPolicyName(String policyName) 44 { 45 this.policyName = policyName; 46 } 47 48 public void setTriggerParentRules(boolean triggerParentRules) 49 { 50 this.triggerParentRules = triggerParentRules; 51 } 52 53 public void registerRuleTrigger() 54 { 55 if (policyName == null) 56 { 57 throw new RuleServiceException(ERR_POLICY_NAME_NOT_SET); 58 } 59 60 this.policyComponent.bindClassBehaviour( 61 QName.createQName(this.policyNamespace, this.policyName), 62 this, 63 new JavaBehaviour(this, "policyBehaviour")); 64 } 65 66 public void policyBehaviour(NodeRef nodeRef) 67 { 68 if (triggerParentRules == true) 69 { 70 List <ChildAssociationRef> parentsAssocRefs = this.nodeService.getParentAssocs(nodeRef); 71 for (ChildAssociationRef parentAssocRef : parentsAssocRefs) 72 { 73 triggerRules(parentAssocRef.getParentRef(), nodeRef); 74 } 75 } 76 else 77 { 78 triggerRules(nodeRef, nodeRef); 79 } 80 } 81 } 82 | Popular Tags |