From 19c95ce58f7c78035b2d7e1cc2cfe8cad7413d83 Mon Sep 17 00:00:00 2001 From: Derek Hulley Date: Mon, 18 Dec 2006 15:28:54 +0000 Subject: [PATCH] Merge 1.4 to HEAD (excl records management) svn merge svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4306 svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4307 . rm -rf root/projects/records-mgmt git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4637 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../repo/node/AbstractNodeServiceImpl.java | 34 +++++++++++++++++++ .../repo/node/NodeServicePolicies.java | 25 ++++++++++++++ .../repo/node/db/DbNodeServiceImpl.java | 2 ++ .../AssociationPolicyRegistration.java | 17 ++++++---- .../registration/ClassPolicyRegistration.java | 9 +++-- .../registration/PolicyRegistration.java | 24 +++++++++++-- 6 files changed, 99 insertions(+), 12 deletions(-) diff --git a/source/java/org/alfresco/repo/node/AbstractNodeServiceImpl.java b/source/java/org/alfresco/repo/node/AbstractNodeServiceImpl.java index 4f777ab1bf..da31bb8254 100644 --- a/source/java/org/alfresco/repo/node/AbstractNodeServiceImpl.java +++ b/source/java/org/alfresco/repo/node/AbstractNodeServiceImpl.java @@ -28,6 +28,7 @@ import org.alfresco.model.ContentModel; import org.alfresco.repo.domain.PropertyValue; import org.alfresco.repo.node.NodeServicePolicies.BeforeAddAspectPolicy; import org.alfresco.repo.node.NodeServicePolicies.BeforeCreateChildAssociationPolicy; +import org.alfresco.repo.node.NodeServicePolicies.BeforeCreateNodeAssociationPolicy; import org.alfresco.repo.node.NodeServicePolicies.BeforeCreateNodePolicy; import org.alfresco.repo.node.NodeServicePolicies.BeforeCreateStorePolicy; import org.alfresco.repo.node.NodeServicePolicies.BeforeDeleteChildAssociationPolicy; @@ -37,6 +38,7 @@ import org.alfresco.repo.node.NodeServicePolicies.BeforeUpdateNodePolicy; import org.alfresco.repo.node.NodeServicePolicies.OnAddAspectPolicy; import org.alfresco.repo.node.NodeServicePolicies.OnCreateAssociationPolicy; import org.alfresco.repo.node.NodeServicePolicies.OnCreateChildAssociationPolicy; +import org.alfresco.repo.node.NodeServicePolicies.OnCreateNodeAssociationPolicy; import org.alfresco.repo.node.NodeServicePolicies.OnCreateNodePolicy; import org.alfresco.repo.node.NodeServicePolicies.OnCreateStorePolicy; import org.alfresco.repo.node.NodeServicePolicies.OnDeleteAssociationPolicy; @@ -110,6 +112,8 @@ public abstract class AbstractNodeServiceImpl implements NodeService private ClassPolicyDelegate onAddAspectDelegate; private ClassPolicyDelegate beforeRemoveAspectDelegate; private ClassPolicyDelegate onRemoveAspectDelegate; + private AssociationPolicyDelegate beforeCreateNodeAssociationDelegate; + private AssociationPolicyDelegate onCreateNodeAssociationDelegate; private AssociationPolicyDelegate beforeCreateChildAssociationDelegate; private AssociationPolicyDelegate onCreateChildAssociationDelegate; private AssociationPolicyDelegate beforeDeleteChildAssociationDelegate; @@ -183,6 +187,8 @@ public abstract class AbstractNodeServiceImpl implements NodeService beforeRemoveAspectDelegate = policyComponent.registerClassPolicy(NodeServicePolicies.BeforeRemoveAspectPolicy.class); onRemoveAspectDelegate = policyComponent.registerClassPolicy(NodeServicePolicies.OnRemoveAspectPolicy.class); + beforeCreateNodeAssociationDelegate = policyComponent.registerAssociationPolicy(NodeServicePolicies.BeforeCreateNodeAssociationPolicy.class); + onCreateNodeAssociationDelegate = policyComponent.registerAssociationPolicy(NodeServicePolicies.OnCreateNodeAssociationPolicy.class); beforeCreateChildAssociationDelegate = policyComponent.registerAssociationPolicy(NodeServicePolicies.BeforeCreateChildAssociationPolicy.class); onCreateChildAssociationDelegate = policyComponent.registerAssociationPolicy(NodeServicePolicies.OnCreateChildAssociationPolicy.class); beforeDeleteChildAssociationDelegate = policyComponent.registerAssociationPolicy(NodeServicePolicies.BeforeDeleteChildAssociationPolicy.class); @@ -392,6 +398,34 @@ public abstract class AbstractNodeServiceImpl implements NodeService NodeServicePolicies.OnRemoveAspectPolicy policy = onRemoveAspectDelegate.get(nodeRef, aspectTypeQName); policy.onRemoveAspect(nodeRef, aspectTypeQName); } + + /** + * @see NodeServicePolicies.BeforeCreateNodeAssociationPolicy#beforeCreateChildAssociation(NodeRef, + * NodeRef, QName, QName) + */ + protected void invokeBeforeCreateNodeAssociation(NodeRef parentNodeRef, QName assocTypeQName, QName assocQName) + { + // get qnames to invoke against + Set qnames = getTypeAndAspectQNames(parentNodeRef); + // execute policy for node type + NodeServicePolicies.BeforeCreateNodeAssociationPolicy policy = beforeCreateNodeAssociationDelegate.get(parentNodeRef, qnames, assocTypeQName); + policy.beforeCreateNodeAssociation(parentNodeRef, assocTypeQName, assocQName); + } + + /** + * @see NodeServicePolicies.OnCreateNodeAssociationPolicy#onCreateChildAssociation(ChildAssociationRef) + */ + protected void invokeOnCreateNodeAssociation(ChildAssociationRef childAssocRef) + { + // Get the parent reference and the assoc type qName + NodeRef parentNodeRef = childAssocRef.getParentRef(); + QName assocTypeQName = childAssocRef.getTypeQName(); + // get qnames to invoke against + Set qnames = getTypeAndAspectQNames(parentNodeRef); + // execute policy for node type and aspects + NodeServicePolicies.OnCreateNodeAssociationPolicy policy = onCreateNodeAssociationDelegate.get(parentNodeRef, qnames, assocTypeQName); + policy.onCreateNodeAssociation(childAssocRef); + } /** * @see NodeServicePolicies.BeforeCreateChildAssociationPolicy#beforeCreateChildAssociation(NodeRef, diff --git a/source/java/org/alfresco/repo/node/NodeServicePolicies.java b/source/java/org/alfresco/repo/node/NodeServicePolicies.java index 288e24606b..8438acffa0 100644 --- a/source/java/org/alfresco/repo/node/NodeServicePolicies.java +++ b/source/java/org/alfresco/repo/node/NodeServicePolicies.java @@ -200,6 +200,31 @@ public interface NodeServicePolicies */ public void onRemoveAspect(NodeRef nodeRef, QName aspectTypeQName); } + + public interface BeforeCreateNodeAssociationPolicy extends AssociationPolicy + { + /** + * Called before a new node is created with the details of the new child association. + * + * @param parentNodeRef + * @param assocTypeQName the type of the association + * @param assocQName the name of the association + */ + public void beforeCreateNodeAssociation( + NodeRef parentNodeRef, + QName assocTypeQName, + QName assocQName); + } + + public interface OnCreateNodeAssociationPolicy extends AssociationPolicy + { + /** + * Called after a node is created with the created association details + * + * @param childAssocRef the child association that has been created + */ + public void onCreateNodeAssociation(ChildAssociationRef childAssocRef); + } public interface BeforeCreateChildAssociationPolicy extends AssociationPolicy { diff --git a/source/java/org/alfresco/repo/node/db/DbNodeServiceImpl.java b/source/java/org/alfresco/repo/node/db/DbNodeServiceImpl.java index 127a1a000b..65d0f59fd8 100644 --- a/source/java/org/alfresco/repo/node/db/DbNodeServiceImpl.java +++ b/source/java/org/alfresco/repo/node/db/DbNodeServiceImpl.java @@ -267,6 +267,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl // Invoke policy behaviour invokeBeforeUpdateNode(parentRef); invokeBeforeCreateNode(parentRef, assocTypeQName, assocQName, nodeTypeQName); + invokeBeforeCreateNodeAssociation(parentRef, assocTypeQName, assocQName); // get the store that the parent belongs to StoreRef storeRef = parentRef.getStoreRef(); @@ -318,6 +319,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl // Invoke policy behaviour invokeOnCreateNode(childAssocRef); + invokeOnCreateNodeAssociation(childAssocRef); invokeOnUpdateNode(parentRef); if (propertiesAfter != null) { diff --git a/source/java/org/alfresco/repo/policy/registration/AssociationPolicyRegistration.java b/source/java/org/alfresco/repo/policy/registration/AssociationPolicyRegistration.java index 31e1cfc88f..cc843d3b6a 100644 --- a/source/java/org/alfresco/repo/policy/registration/AssociationPolicyRegistration.java +++ b/source/java/org/alfresco/repo/policy/registration/AssociationPolicyRegistration.java @@ -32,14 +32,17 @@ public class AssociationPolicyRegistration extends PolicyRegistration @Override public void register() { - // Register the association behaviour - if (this.associationType == null) - { - this.policyComponent.bindAssociationBehaviour(this.policyName, this.className, this.behaviour); - } - else + for (QName policyName : this.policyNames) { - this.policyComponent.bindAssociationBehaviour(this.policyName, this.className, this.associationType, this.behaviour); + // Register the association behaviour + if (this.associationType == null) + { + this.policyComponent.bindAssociationBehaviour(policyName, this.className, this.behaviour); + } + else + { + this.policyComponent.bindAssociationBehaviour(policyName, this.className, this.associationType, this.behaviour); + } } } diff --git a/source/java/org/alfresco/repo/policy/registration/ClassPolicyRegistration.java b/source/java/org/alfresco/repo/policy/registration/ClassPolicyRegistration.java index c21cf5eee0..d207efe5b6 100644 --- a/source/java/org/alfresco/repo/policy/registration/ClassPolicyRegistration.java +++ b/source/java/org/alfresco/repo/policy/registration/ClassPolicyRegistration.java @@ -3,6 +3,8 @@ */ package org.alfresco.repo.policy.registration; +import org.alfresco.service.namespace.QName; + /** * Deal with the registration of a class policy * @@ -17,8 +19,11 @@ public class ClassPolicyRegistration extends PolicyRegistration @Override public void register() { - // Register the class behaviour - this.policyComponent.bindClassBehaviour(this.policyName, this.className, this.behaviour); + for (QName policyName : this.policyNames) + { + // Register the class behaviour + this.policyComponent.bindClassBehaviour(policyName, this.className, this.behaviour); + } } } diff --git a/source/java/org/alfresco/repo/policy/registration/PolicyRegistration.java b/source/java/org/alfresco/repo/policy/registration/PolicyRegistration.java index 89eda6c7ce..30654123dd 100644 --- a/source/java/org/alfresco/repo/policy/registration/PolicyRegistration.java +++ b/source/java/org/alfresco/repo/policy/registration/PolicyRegistration.java @@ -3,6 +3,9 @@ */ package org.alfresco.repo.policy.registration; +import java.util.ArrayList; +import java.util.List; + import org.alfresco.repo.policy.Behaviour; import org.alfresco.repo.policy.PolicyComponent; import org.alfresco.service.namespace.QName; @@ -17,8 +20,8 @@ public abstract class PolicyRegistration /** The policy componenet **/ protected PolicyComponent policyComponent; - /** The policy name **/ - protected QName policyName; + /** The policy names **/ + protected List policyNames; /** The class name **/ protected QName className; @@ -43,7 +46,22 @@ public abstract class PolicyRegistration */ public void setPolicyName(String policyName) { - this.policyName = QName.createQName(policyName); + this.policyNames = new ArrayList(1); + this.policyNames.add(QName.createQName(policyName)); + } + + /** + * Set the policy names. The behaviour will be added for each for the policies. + * + * @param policyNames the policy names + */ + public void setPolicyNames(List policyNames) + { + this.policyNames = new ArrayList(policyNames.size()); + for (String policyName : policyNames) + { + this.policyNames.add(QName.createQName(policyName)); + } } /**