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.namespace.NamespaceService; 32 import org.alfresco.service.namespace.QName; 33 34 39 public class ActionableAspect 40 { 41 public static final QName ASSOC_NAME_SAVEDACTIONFOLDER = QName.createQName(ContentModel.ACTION_MODEL_URI, "savedActionFolder"); 42 public static final QName ASSOC_NAME_SAVEDRULESFOLDER = QName.createQName(ContentModel.ACTION_MODEL_URI, "savedRuleFolder"); 43 44 private Behaviour onAddAspectBehaviour; 45 46 private PolicyComponent policyComponent; 47 48 private NodeService nodeService; 49 50 public void setPolicyComponent(PolicyComponent policyComponent) 51 { 52 this.policyComponent = policyComponent; 53 } 54 55 public void setNodeService(NodeService nodeService) 56 { 57 this.nodeService = nodeService; 58 } 59 60 public void init() 61 { 62 this.policyComponent.bindClassBehaviour( 63 QName.createQName(NamespaceService.ALFRESCO_URI, "onCopyNode"), 64 ContentModel.ASPECT_ACTIONABLE, 65 new JavaBehaviour(this, "onCopyNode")); 66 this.policyComponent.bindClassBehaviour( 67 QName.createQName(NamespaceService.ALFRESCO_URI, "onCopyComplete"), 68 ContentModel.ASPECT_ACTIONABLE, 69 new JavaBehaviour(this, "onCopyComplete")); 70 71 this.onAddAspectBehaviour = new JavaBehaviour(this, "onAddAspect"); 72 this.policyComponent.bindClassBehaviour( 73 QName.createQName(NamespaceService.ALFRESCO_URI, "onAddAspect"), 74 this, 75 onAddAspectBehaviour); 76 } 77 78 83 public void onAddAspect(NodeRef nodeRef, QName aspectTypeQName) 84 { 85 if (ContentModel.ASPECT_ACTIONABLE.equals(aspectTypeQName) == true) 86 { 87 List <ChildAssociationRef> assocs = this.nodeService.getChildAssocs(nodeRef, ASSOC_NAME_SAVEDACTIONFOLDER); 88 if (assocs.size() == 0) 89 { 90 this.nodeService.createNode(nodeRef, 92 ContentModel.ASSOC_SAVED_ACTION_FOLDERS, 93 ASSOC_NAME_SAVEDACTIONFOLDER, 94 ContentModel.TYPE_SAVED_ACTION_FOLDER); 95 } 96 97 List <ChildAssociationRef> assocs2 = this.nodeService.getChildAssocs(nodeRef, ASSOC_NAME_SAVEDRULESFOLDER); 98 if (assocs2.size() == 0) 99 { 100 this.nodeService.createNode(nodeRef, 102 ContentModel.ASSOC_SAVED_ACTION_FOLDERS, 103 ASSOC_NAME_SAVEDRULESFOLDER, 104 ContentModel.TYPE_SAVED_ACTION_FOLDER); 105 } 106 } 107 } 108 109 public void onCopyNode( 110 QName classRef, 111 NodeRef sourceNodeRef, 112 StoreRef destinationStoreRef, 113 boolean copyToNewNode, 114 PolicyScope copyDetails) 115 { 116 copyDetails.addAspect(ContentModel.ASPECT_ACTIONABLE); 117 118 List <ChildAssociationRef> assocs = this.nodeService.getChildAssocs(sourceNodeRef); 119 for (ChildAssociationRef assoc : assocs) 120 { 121 if (assoc.getTypeQName().equals(ContentModel.ASSOC_SAVED_ACTION_FOLDERS) == true) 122 { 123 copyDetails.addChildAssociation(classRef, assoc, true); 124 } 125 } 126 127 this.onAddAspectBehaviour.disable(); 128 } 129 130 public void onCopyComplete( 131 QName classRef, 132 NodeRef sourceNodeRef, 133 NodeRef destinationRef, 134 Map <NodeRef, NodeRef> copyMap) 135 { 136 this.onAddAspectBehaviour.enable(); 137 } 138 } 139 | Popular Tags |