Enhanced 'beforeCreateChildAssociaton' and 'onCreateChildAssociation' to carry an 'isNewNode' flag.

Fixed Lock and Rules to react correctly to this new information.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6003 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2007-06-18 11:29:00 +00:00
parent 832c1b599e
commit 6e0c406488
9 changed files with 106 additions and 45 deletions

View File

@@ -439,19 +439,19 @@ public abstract class AbstractNodeServiceImpl implements NodeService
* @see NodeServicePolicies.BeforeCreateChildAssociationPolicy#beforeCreateChildAssociation(NodeRef,
* NodeRef, QName, QName)
*/
protected void invokeBeforeCreateChildAssociation(NodeRef parentNodeRef, NodeRef childNodeRef, QName assocTypeQName, QName assocQName)
protected void invokeBeforeCreateChildAssociation(NodeRef parentNodeRef, NodeRef childNodeRef, QName assocTypeQName, QName assocQName, boolean isNewNode)
{
// get qnames to invoke against
Set<QName> qnames = getTypeAndAspectQNames(parentNodeRef);
// execute policy for node type
NodeServicePolicies.BeforeCreateChildAssociationPolicy policy = beforeCreateChildAssociationDelegate.get(parentNodeRef, qnames, assocTypeQName);
policy.beforeCreateChildAssociation(parentNodeRef, childNodeRef, assocTypeQName, assocQName);
policy.beforeCreateChildAssociation(parentNodeRef, childNodeRef, assocTypeQName, assocQName, isNewNode);
}
/**
* @see NodeServicePolicies.OnCreateChildAssociationPolicy#onCreateChildAssociation(ChildAssociationRef)
*/
protected void invokeOnCreateChildAssociation(ChildAssociationRef childAssocRef)
protected void invokeOnCreateChildAssociation(ChildAssociationRef childAssocRef, boolean isNewNode)
{
// Get the parent reference and the assoc type qName
NodeRef parentNodeRef = childAssocRef.getParentRef();
@@ -460,7 +460,7 @@ public abstract class AbstractNodeServiceImpl implements NodeService
Set<QName> qnames = getTypeAndAspectQNames(parentNodeRef);
// execute policy for node type and aspects
NodeServicePolicies.OnCreateChildAssociationPolicy policy = onCreateChildAssociationDelegate.get(parentNodeRef, qnames, assocTypeQName);
policy.onCreateChildAssociation(childAssocRef);
policy.onCreateChildAssociation(childAssocRef, isNewNode);
}
/**

View File

@@ -239,16 +239,18 @@ public interface NodeServicePolicies
/**
* Called before a node child association is created.
*
* @param parentNodeRef
* @param childNodeRef
* @param assocTypeQName the type of the association
* @param assocQName the name of the association
* @param parentNodeRef the parent node reference
* @param childNodeRef the child node reference
* @param assocTypeQName the type of the association
* @param assocQName the name of the association
* @param isNewNode <tt>true</tt> if the node is new or <tt>false</tt> if the node is being linked in
*/
public void beforeCreateChildAssociation(
NodeRef parentNodeRef,
NodeRef childNodeRef,
QName assocTypeQName,
QName assocQName);
QName assocQName,
boolean isNewNode);
}
public interface OnCreateChildAssociationPolicy extends AssociationPolicy
@@ -256,9 +258,10 @@ public interface NodeServicePolicies
/**
* Called after a node child association has been created.
*
* @param childAssocRef the child association that has been created
* @param childAssocRef the child association that has been created
* @param isNewNode <tt>true</tt> if the node is new or <tt>false</tt> if the node is being linked in
*/
public void onCreateChildAssociation(ChildAssociationRef childAssocRef);
public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean isNewNode);
}
public interface BeforeDeleteChildAssociationPolicy extends AssociationPolicy

View File

@@ -322,7 +322,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
NodeRef childNodeRef = childNode.getNodeRef();
// We now have enough to declare the child association creation
invokeBeforeCreateChildAssociation(parentRef, childNodeRef, assocTypeQName, assocQName);
invokeBeforeCreateChildAssociation(parentRef, childNodeRef, assocTypeQName, assocQName, true);
// Get the parent node
Node parentNode = getNodeNotNull(parentRef);
@@ -354,7 +354,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
// Invoke policy behaviour
invokeOnCreateNode(childAssocRef);
invokeOnCreateChildAssociation(childAssocRef);
invokeOnCreateChildAssociation(childAssocRef, true);
if (propertiesAfter != null)
{
invokeOnUpdateProperties(childAssocRef.getChildRef(), propertiesBefore, propertiesAfter);
@@ -427,7 +427,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
else
{
invokeBeforeDeleteChildAssociation(oldAssocRef);
invokeBeforeCreateChildAssociation(newParentRef, nodeToMoveRef, assocTypeQName, assocQName);
invokeBeforeCreateChildAssociation(newParentRef, nodeToMoveRef, assocTypeQName, assocQName, false);
}
// remove the child assoc from the old parent
@@ -467,7 +467,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
}
else
{
invokeOnCreateChildAssociation(newAssoc.getChildAssocRef());
invokeOnCreateChildAssociation(newAssoc.getChildAssocRef(), false);
invokeOnDeleteChildAssociation(oldAssoc.getChildAssocRef());
}
invokeOnMoveNode(oldAssocRef, newAssocRef);
@@ -741,7 +741,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
public ChildAssociationRef addChild(NodeRef parentRef, NodeRef childRef, QName assocTypeQName, QName assocQName)
{
// Invoke policy behaviours
invokeBeforeCreateChildAssociation(parentRef, childRef, assocTypeQName, assocQName);
invokeBeforeCreateChildAssociation(parentRef, childRef, assocTypeQName, assocQName, false);
// get the parent node and ensure that it is a container node
Node parentNode = getNodeNotNull(parentRef);
@@ -764,7 +764,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
getPaths(childNodeRef, false);
// Invoke policy behaviours
invokeOnCreateChildAssociation(assocRef);
invokeOnCreateChildAssociation(assocRef, false);
return assoc.getChildAssocRef();
}

View File

@@ -109,9 +109,12 @@ public class NodeIndexer
indexer.deleteNode(childAssocRef);
}
public void onCreateChildAssociation(ChildAssociationRef childAssocRef)
public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean isNew)
{
indexer.createChildRelationship(childAssocRef);
if (!isNew)
{
indexer.createChildRelationship(childAssocRef);
}
}
public void onDeleteChildAssociation(ChildAssociationRef childAssocRef)

View File

@@ -231,6 +231,9 @@ public class IncompleteNodeTagger
}
}
/**
* {@inheritDoc}
*/
public void onCreateNode(ChildAssociationRef childAssocRef)
{
NodeRef nodeRef = childAssocRef.getChildRef();
@@ -238,6 +241,9 @@ public class IncompleteNodeTagger
saveAssoc(nodeRef, null);
}
/**
* {@inheritDoc}
*/
public void onUpdateProperties(
NodeRef nodeRef,
Map<QName, Serializable> before,
@@ -247,6 +253,8 @@ public class IncompleteNodeTagger
}
/**
* {@inheritDoc}
* <p>
* Save the node for checking of properties.
* The {@link org.alfresco.model.ContentModel#ASPECT_INCOMPLETE incomplete} aspect is
* not processed.
@@ -279,20 +287,21 @@ public class IncompleteNodeTagger
}
/**
* @see AssocSourceTypeIntegrityEvent
* @see AssocTargetTypeIntegrityEvent
* @see AssocSourceMultiplicityIntegrityEvent
* @see AssocTargetMultiplicityIntegrityEvent
* @see AssocTargetRoleIntegrityEvent
* {@inheritDoc}
* <p>
* This only saves the node for checking if it is <i>not</i> new. The create of the
* node will handle it.
*/
public void onCreateChildAssociation(ChildAssociationRef childAssocRef)
public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean isNew)
{
saveAssoc(childAssocRef.getParentRef(), childAssocRef.getTypeQName());
if (!isNew)
{
saveAssoc(childAssocRef.getParentRef(), childAssocRef.getTypeQName());
}
}
/**
* @see AssocSourceMultiplicityIntegrityEvent
* @see AssocTargetMultiplicityIntegrityEvent
* {@inheritDoc}
*/
public void onDeleteChildAssociation(ChildAssociationRef childAssocRef)
{
@@ -300,10 +309,7 @@ public class IncompleteNodeTagger
}
/**
* @see AssocSourceTypeIntegrityEvent
* @see AssocTargetTypeIntegrityEvent
* @see AssocSourceMultiplicityIntegrityEvent
* @see AssocTargetMultiplicityIntegrityEvent
* {@inheritDoc}
*/
public void onCreateAssociation(AssociationRef nodeAssocRef)
{
@@ -311,8 +317,7 @@ public class IncompleteNodeTagger
}
/**
* @see AssocSourceMultiplicityIntegrityEvent
* @see AssocTargetMultiplicityIntegrityEvent
* {@inheritDoc}
*/
public void onDeleteAssociation(AssociationRef nodeAssocRef)
{

View File

@@ -328,7 +328,7 @@ public class IntegrityChecker
save(event);
// check that the multiplicity and other properties of the new association are allowed
onCreateChildAssociation(childAssocRef);
onCreateChildAssociation(childAssocRef, false);
// check mandatory aspects
event = new AspectsIntegrityEvent(nodeService, dictionaryService, childRef);
@@ -426,14 +426,21 @@ public class IntegrityChecker
}
/**
* This handles the creation of secondary child associations.
*
* @see AssocSourceTypeIntegrityEvent
* @see AssocTargetTypeIntegrityEvent
* @see AssocSourceMultiplicityIntegrityEvent
* @see AssocTargetMultiplicityIntegrityEvent
* @see AssocTargetRoleIntegrityEvent
*/
public void onCreateChildAssociation(ChildAssociationRef childAssocRef)
public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean isNew)
{
if (isNew)
{
return;
}
IntegrityEvent event = null;
// check source type
event = new AssocSourceTypeIntegrityEvent(