1 17 package org.alfresco.repo.action; 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 ActionsAspect 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 ActionModel.ASPECT_ACTIONS, 71 new JavaBehaviour(this, "onCopyNode")); 72 this.policyComponent.bindClassBehaviour( 73 QName.createQName(NamespaceService.ALFRESCO_URI, "onCopyComplete"), 74 ActionModel.ASPECT_ACTIONS, 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 ActionModel.ASPECT_ACTIONS, 81 onAddAspectBehaviour); 82 } 83 84 85 86 93 public void disbleOnAddAspect() 94 { 95 this.onAddAspectBehaviour.disable(); 96 } 97 98 105 public void enableOnAddAspect() 106 { 107 this.onAddAspectBehaviour.enable(); 108 } 109 110 115 public void onAddAspect(NodeRef nodeRef, QName aspectTypeQName) 116 { 117 this.ruleService.disableRules(nodeRef); 118 try 119 { 120 this.nodeService.createNode( 121 nodeRef, 122 ActionModel.ASSOC_ACTION_FOLDER, 123 ActionModel.ASSOC_ACTION_FOLDER, 124 ContentModel.TYPE_SYSTEM_FOLDER); 125 } 126 finally 127 { 128 this.ruleService.enableRules(nodeRef); 129 } 130 } 131 132 public void onCopyNode( 133 QName classRef, 134 NodeRef sourceNodeRef, 135 StoreRef destinationStoreRef, 136 boolean copyToNewNode, 137 PolicyScope copyDetails) 138 { 139 copyDetails.addAspect(ActionModel.ASPECT_ACTIONS); 140 141 List <ChildAssociationRef> assocs = this.nodeService.getChildAssocs( 142 sourceNodeRef, 143 RegexQNamePattern.MATCH_ALL, 144 ActionModel.ASSOC_ACTION_FOLDER); 145 for (ChildAssociationRef assoc : assocs) 146 { 147 copyDetails.addChildAssociation(classRef, assoc, true); 148 } 149 150 this.onAddAspectBehaviour.disable(); 151 } 152 153 public void onCopyComplete( 154 QName classRef, 155 NodeRef sourceNodeRef, 156 NodeRef destinationRef, 157 boolean copyToNew, 158 Map <NodeRef, NodeRef> copyMap) 159 { 160 this.onAddAspectBehaviour.enable(); 161 } 162 } 163 | Popular Tags |