1 17 package org.alfresco.repo.rule; 18 19 import java.util.List ; 20 import java.util.Map ; 21 22 import org.alfresco.model.ContentModel; 23 import org.alfresco.repo.policy.Behaviour; 24 import org.alfresco.repo.policy.JavaBehaviour; 25 import org.alfresco.repo.policy.PolicyComponent; 26 import org.alfresco.repo.policy.PolicyScope; 27 import org.alfresco.service.cmr.repository.ChildAssociationRef; 28 import org.alfresco.service.cmr.repository.NodeRef; 29 import org.alfresco.service.cmr.repository.NodeService; 30 import org.alfresco.service.cmr.repository.StoreRef; 31 import org.alfresco.service.cmr.rule.RuleService; 32 import org.alfresco.service.namespace.NamespaceService; 33 import org.alfresco.service.namespace.QName; 34 import org.alfresco.service.namespace.RegexQNamePattern; 35 36 41 public class RulesAspect 42 { 43 private Behaviour onAddAspectBehaviour; 44 45 private PolicyComponent policyComponent; 46 47 private RuleService ruleService; 48 49 private NodeService nodeService; 50 51 public void setPolicyComponent(PolicyComponent policyComponent) 52 { 53 this.policyComponent = policyComponent; 54 } 55 56 public void setNodeService(NodeService nodeService) 57 { 58 this.nodeService = nodeService; 59 } 60 61 public void setRuleService(RuleService ruleService) 62 { 63 this.ruleService = ruleService; 64 } 65 66 public void init() 67 { 68 this.policyComponent.bindClassBehaviour( 69 QName.createQName(NamespaceService.ALFRESCO_URI, "onCopyNode"), 70 RuleModel.ASPECT_RULES, 71 new JavaBehaviour(this, "onCopyNode")); 72 this.policyComponent.bindClassBehaviour( 73 QName.createQName(NamespaceService.ALFRESCO_URI, "onCopyComplete"), 74 RuleModel.ASPECT_RULES, 75 new JavaBehaviour(this, "onCopyComplete")); 76 77 this.onAddAspectBehaviour = new JavaBehaviour(this, "onAddAspect"); 78 this.policyComponent.bindClassBehaviour( 79 QName.createQName(NamespaceService.ALFRESCO_URI, "onAddAspect"), 80 RuleModel.ASPECT_RULES, 81 onAddAspectBehaviour); 82 } 83 84 91 public void disbleOnAddAspect() 92 { 93 this.onAddAspectBehaviour.disable(); 94 } 95 96 103 public void enableOnAddAspect() 104 { 105 this.onAddAspectBehaviour.enable(); 106 } 107 108 113 public void onAddAspect(NodeRef nodeRef, QName aspectTypeQName) 114 { 115 this.ruleService.disableRules(nodeRef); 116 try 117 { 118 int count = this.nodeService.getChildAssocs(nodeRef, RuleModel.ASSOC_RULE_FOLDER, RuleModel.ASSOC_RULE_FOLDER).size(); 119 if (count == 0) 120 { 121 this.nodeService.createNode( 122 nodeRef, 123 RuleModel.ASSOC_RULE_FOLDER, 124 RuleModel.ASSOC_RULE_FOLDER, 125 ContentModel.TYPE_SYSTEM_FOLDER); 126 } 127 } 128 finally 129 { 130 this.ruleService.enableRules(nodeRef); 131 } 132 } 133 134 public void onCopyNode( 135 QName classRef, 136 NodeRef sourceNodeRef, 137 StoreRef destinationStoreRef, 138 boolean copyToNewNode, 139 PolicyScope copyDetails) 140 { 141 copyDetails.addAspect(RuleModel.ASPECT_RULES); 142 143 List <ChildAssociationRef> assocs = this.nodeService.getChildAssocs( 144 sourceNodeRef, 145 RegexQNamePattern.MATCH_ALL, 146 RuleModel.ASSOC_RULE_FOLDER); 147 for (ChildAssociationRef assoc : assocs) 148 { 149 copyDetails.addChildAssociation(classRef, assoc, true); 150 } 151 152 this.onAddAspectBehaviour.disable(); 153 } 154 155 public void onCopyComplete( 156 QName classRef, 157 NodeRef sourceNodeRef, 158 NodeRef destinationRef, 159 boolean copyToNew, 160 Map <NodeRef, NodeRef> copyMap) 161 { 162 this.onAddAspectBehaviour.enable(); 163 } 164 } 165 | Popular Tags |