1 17 18 package org.alfresco.repo.coci; 19 20 import org.alfresco.model.ContentModel; 21 import org.alfresco.repo.policy.JavaBehaviour; 22 import org.alfresco.repo.policy.PolicyComponent; 23 import org.alfresco.repo.policy.PolicyScope; 24 import org.alfresco.service.cmr.lock.LockService; 25 import org.alfresco.service.cmr.repository.NodeRef; 26 import org.alfresco.service.cmr.repository.NodeService; 27 import org.alfresco.service.cmr.repository.StoreRef; 28 import org.alfresco.service.namespace.NamespaceService; 29 import org.alfresco.service.namespace.QName; 30 31 public class WorkingCopyAspect 32 { 33 36 private PolicyComponent policyComponent; 37 38 41 private NodeService nodeService; 42 43 46 private LockService lockService; 47 48 53 public void setPolicyComponent(PolicyComponent policyComponent) 54 { 55 this.policyComponent = policyComponent; 56 } 57 58 63 public void setNodeService(NodeService nodeService) 64 { 65 this.nodeService = nodeService; 66 } 67 68 73 public void setLockService(LockService lockService) 74 { 75 this.lockService = lockService; 76 } 77 78 81 public void init() 82 { 83 this.policyComponent.bindClassBehaviour( 85 QName.createQName(NamespaceService.ALFRESCO_URI, "onCopyNode"), 86 ContentModel.ASPECT_WORKING_COPY, 87 new JavaBehaviour(this, "onCopy")); 88 89 this.policyComponent.bindClassBehaviour( 91 QName.createQName(NamespaceService.ALFRESCO_URI, "beforeDeleteNode"), 92 ContentModel.ASPECT_WORKING_COPY, 93 new JavaBehaviour(this, "beforeDeleteNode")); 94 } 95 96 101 public void onCopy( 102 QName sourceClassRef, 103 NodeRef sourceNodeRef, 104 StoreRef destinationStoreRef, 105 boolean copyToNewNode, 106 PolicyScope copyDetails) 107 { 108 if (copyToNewNode == false) 109 { 110 copyDetails.removeProperty(ContentModel.PROP_NAME); 112 } 113 114 } 116 117 122 public void beforeDeleteNode(NodeRef nodeRef) 123 { 124 if (this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY) == true && 127 this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_COPIEDFROM) == true) 128 { 129 NodeRef origNodeRef = (NodeRef)this.nodeService.getProperty(nodeRef, ContentModel.PROP_COPY_REFERENCE); 131 if (origNodeRef != null) 132 { 133 this.lockService.unlock(origNodeRef); 135 } 136 } 137 } 138 139 } 140 | Popular Tags |