Lock implementation was listening for beforeUpdateNode on the parent node.

We no longer raise update calls for the parent nodes, so this had to move to onBeforeCreateChildAssociation.
The node service was calling oncreateNodeAssociation, instead of the correct child association behaviour.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5974 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2007-06-15 11:19:32 +00:00
parent fa49ba7916
commit 5cacfe861e
5 changed files with 110 additions and 45 deletions

View File

@@ -35,10 +35,13 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.copy.CopyServicePolicies;
import org.alfresco.repo.node.NodeServicePolicies;
import org.alfresco.repo.policy.JavaBehaviour; import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent; import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.policy.PolicyScope; import org.alfresco.repo.policy.PolicyScope;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.version.VersionServicePolicies;
import org.alfresco.service.cmr.lock.LockService; import org.alfresco.service.cmr.lock.LockService;
import org.alfresco.service.cmr.lock.LockStatus; import org.alfresco.service.cmr.lock.LockStatus;
import org.alfresco.service.cmr.lock.LockType; import org.alfresco.service.cmr.lock.LockType;
@@ -62,7 +65,13 @@ import org.alfresco.service.namespace.QName;
* *
* @author Roy Wetherall * @author Roy Wetherall
*/ */
public class LockServiceImpl implements LockService public class LockServiceImpl implements LockService,
NodeServicePolicies.BeforeCreateChildAssociationPolicy,
NodeServicePolicies.BeforeUpdateNodePolicy,
NodeServicePolicies.BeforeDeleteNodePolicy,
CopyServicePolicies.OnCopyNodePolicy,
VersionServicePolicies.BeforeCreateVersionPolicy,
VersionServicePolicies.OnCreateVersionPolicy
{ {
/** /**
* The node service * The node service
@@ -155,21 +164,34 @@ public class LockServiceImpl implements LockService
public void initialise() public void initialise()
{ {
// Register the various class behaviours to enable lock checking // Register the various class behaviours to enable lock checking
this.policyComponent.bindAssociationBehaviour(
QName.createQName(NamespaceService.ALFRESCO_URI, "beforeCreateChildAssociation"),
ContentModel.ASPECT_LOCKABLE,
new JavaBehaviour(this, "beforeCreateChildAssociation"));
this.policyComponent.bindClassBehaviour( this.policyComponent.bindClassBehaviour(
QName.createQName(NamespaceService.ALFRESCO_URI, "beforeCreateVersion"), ContentModel.ASPECT_LOCKABLE, QName.createQName(NamespaceService.ALFRESCO_URI, "beforeUpdateNode"),
new JavaBehaviour(this, "checkForLock")); ContentModel.ASPECT_LOCKABLE,
this.policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "beforeUpdateNode"), new JavaBehaviour(this, "beforeUpdateNode"));
ContentModel.ASPECT_LOCKABLE, new JavaBehaviour(this, "checkForLock")); this.policyComponent.bindClassBehaviour(
this.policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "beforeDeleteNode"), QName.createQName(NamespaceService.ALFRESCO_URI, "beforeDeleteNode"),
ContentModel.ASPECT_LOCKABLE, new JavaBehaviour(this, "checkForLock")); ContentModel.ASPECT_LOCKABLE,
new JavaBehaviour(this, "beforeDeleteNode"));
// Register onCopy class behaviour // Register onCopy class behaviour
this.policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onCopyNode"), this.policyComponent.bindClassBehaviour(
ContentModel.ASPECT_LOCKABLE, new JavaBehaviour(this, "onCopy")); QName.createQName(NamespaceService.ALFRESCO_URI, "onCopyNode"),
ContentModel.ASPECT_LOCKABLE,
new JavaBehaviour(this, "onCopyNode"));
// Register the onCreateVersion behavior for the version aspect // Register the onCreateVersion behavior for the version aspect
this.policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onCreateVersion"), this.policyComponent.bindClassBehaviour(
ContentModel.ASPECT_LOCKABLE, new JavaBehaviour(this, "onCreateVersion")); QName.createQName(NamespaceService.ALFRESCO_URI, "beforeCreateVersion"),
ContentModel.ASPECT_LOCKABLE,
new JavaBehaviour(this, "beforeCreateVersion"));
this.policyComponent.bindClassBehaviour(
QName.createQName(NamespaceService.ALFRESCO_URI, "onCreateVersion"),
ContentModel.ASPECT_LOCKABLE,
new JavaBehaviour(this, "onCreateVersion"));
} }
/** /**
@@ -418,7 +440,7 @@ public class LockServiceImpl implements LockService
} }
/** /**
* @see LockService#checkForLock(NodeRef) * {@inheritDoc}
*/ */
public void checkForLock(NodeRef nodeRef) throws NodeLockedException public void checkForLock(NodeRef nodeRef) throws NodeLockedException
{ {
@@ -439,61 +461,96 @@ public class LockServiceImpl implements LockService
if (LockType.WRITE_LOCK.equals(lockType) == true && if (LockType.WRITE_LOCK.equals(lockType) == true &&
LockStatus.LOCKED.equals(currentLockStatus) == true) LockStatus.LOCKED.equals(currentLockStatus) == true)
{ {
// Error since we are trying to preform an operation // Error since we are trying to preform an operation on a locked node
// on a locked node
throw new NodeLockedException(nodeRef); throw new NodeLockedException(nodeRef);
} }
else if (LockType.READ_ONLY_LOCK.equals(lockType) == true && else if (LockType.READ_ONLY_LOCK.equals(lockType) == true &&
(LockStatus.LOCKED.equals(currentLockStatus) == true || LockStatus.LOCK_OWNER.equals(currentLockStatus) == true)) (LockStatus.LOCKED.equals(currentLockStatus) == true || LockStatus.LOCK_OWNER.equals(currentLockStatus) == true))
{ {
// Error since there is a read only lock on this object // Error since there is a read only lock on this object and all
// and all
// modifications are prevented // modifications are prevented
throw new NodeLockedException(nodeRef); throw new NodeLockedException(nodeRef);
} }
} }
catch (AspectMissingException exception) catch (AspectMissingException exception)
{ {
// Ignore since this indicates that the node does not have // Ignore since this indicates that the node does not have the lock aspect applied
// the lock
// aspect applied
} }
} }
} }
} }
/**
* Ensures that the parent is not locked.
*
* @see #checkForLock(NodeRef)
*/
public void beforeCreateChildAssociation(
NodeRef parentNodeRef,
NodeRef childNodeRef,
QName assocTypeQName,
QName assocQName)
{
checkForLock(parentNodeRef);
}
/**
* Ensures that node is not locked.
*
* @see #checkForLock(NodeRef)
*/
public void beforeUpdateNode(NodeRef nodeRef)
{
checkForLock(nodeRef);
}
/**
* Ensures that node is not locked.
*
* @see #checkForLock(NodeRef)
*/
public void beforeDeleteNode(NodeRef nodeRef)
{
checkForLock(nodeRef);
}
/** /**
* OnCopy behaviour implementation for the lock aspect. * OnCopy behaviour implementation for the lock aspect.
* <p> * <p>
* Ensures that the propety values of the lock aspect are not copied onto * Ensures that the propety values of the lock aspect are not copied onto
* the destination node. * the destination node.
*
* @see org.alfresco.repo.copy.CopyServicePolicies.OnCopyNodePolicy#onCopyNode(QName,
* NodeRef, StoreRef, boolean, PolicyScope)
*/ */
public void onCopy(QName sourceClassRef, NodeRef sourceNodeRef, StoreRef destinationStoreRef, public void onCopyNode(
boolean copyToNewNode, PolicyScope copyDetails) QName classRef,
NodeRef sourceNodeRef,
StoreRef destinationStoreRef,
boolean copyToNewNode,
PolicyScope copyDetails)
{ {
// Add the lock aspect, but do not copy any of the properties // Add the lock aspect, but do not copy any of the properties
copyDetails.addAspect(ContentModel.ASPECT_LOCKABLE); copyDetails.addAspect(ContentModel.ASPECT_LOCKABLE);
} }
/**
* Ensures that node is not locked.
*
* @see #checkForLock(NodeRef)
*/
public void beforeCreateVersion(NodeRef versionableNode)
{
checkForLock(versionableNode);
}
/** /**
* OnCreateVersion behaviour for the lock aspect * OnCreateVersion behaviour for the lock aspect
* <p> * <p>
* Ensures that the property valies of the lock aspect are not 'frozen' in * Ensures that the property valies of the lock aspect are not 'frozen' in
* the version store. * the version store.
*
* @param classRef
* the class reference
* @param versionableNode
* the versionable node reference
* @param versionProperties
* the version properties
* @param nodeDetails
* the details of the node to be versioned
*/ */
public void onCreateVersion(QName classRef, NodeRef versionableNode, Map<String, Serializable> versionProperties, public void onCreateVersion(
QName classRef,
NodeRef versionableNode,
Map<String, Serializable> versionProperties,
PolicyScope nodeDetails) PolicyScope nodeDetails)
{ {
// Add the lock aspect, but do not version the property values // Add the lock aspect, but do not version the property values

View File

@@ -235,7 +235,7 @@ public abstract class AbstractNodeServiceImpl implements NodeService
protected void invokeBeforeCreateNode(NodeRef parentNodeRef, QName assocTypeQName, QName assocQName, QName childNodeTypeQName) protected void invokeBeforeCreateNode(NodeRef parentNodeRef, QName assocTypeQName, QName assocQName, QName childNodeTypeQName)
{ {
// execute policy for node type // execute policy for node type
NodeServicePolicies.BeforeCreateNodePolicy policy = beforeCreateNodeDelegate.get(parentNodeRef, childNodeTypeQName); NodeServicePolicies.BeforeCreateNodePolicy policy = beforeCreateNodeDelegate.get(childNodeTypeQName);
policy.beforeCreateNode(parentNodeRef, assocTypeQName, assocQName, childNodeTypeQName); policy.beforeCreateNode(parentNodeRef, assocTypeQName, assocQName, childNodeTypeQName);
} }

View File

@@ -298,7 +298,6 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
// Invoke policy behaviour // Invoke policy behaviour
invokeBeforeCreateNode(parentRef, assocTypeQName, assocQName, nodeTypeQName); invokeBeforeCreateNode(parentRef, assocTypeQName, assocQName, nodeTypeQName);
invokeBeforeCreateNodeAssociation(parentRef, assocTypeQName, assocQName);
// get the store that the parent belongs to // get the store that the parent belongs to
StoreRef storeRef = parentRef.getStoreRef(); StoreRef storeRef = parentRef.getStoreRef();
@@ -320,6 +319,10 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
// create the node instance // create the node instance
Node childNode = nodeDaoService.newNode(store, newId, nodeTypeQName); Node childNode = nodeDaoService.newNode(store, newId, nodeTypeQName);
NodeRef childNodeRef = childNode.getNodeRef();
// We now have enough to declare the child association creation
invokeBeforeCreateChildAssociation(parentRef, childNodeRef, assocTypeQName, assocQName);
// Get the parent node // Get the parent node
Node parentNode = getNodeNotNull(parentRef); Node parentNode = getNodeNotNull(parentRef);
@@ -351,7 +354,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
// Invoke policy behaviour // Invoke policy behaviour
invokeOnCreateNode(childAssocRef); invokeOnCreateNode(childAssocRef);
invokeOnCreateNodeAssociation(childAssocRef); invokeOnCreateChildAssociation(childAssocRef);
if (propertiesAfter != null) if (propertiesAfter != null)
{ {
invokeOnUpdateProperties(childAssocRef.getChildRef(), propertiesBefore, propertiesAfter); invokeOnUpdateProperties(childAssocRef.getChildRef(), propertiesBefore, propertiesAfter);

View File

@@ -80,10 +80,14 @@ public interface VersionServicePolicies
* WARNING: implementing behaviour for this policy effects the versioning behaviour of the * WARNING: implementing behaviour for this policy effects the versioning behaviour of the
* type the behaviour is registered against. * type the behaviour is registered against.
* *
* @param classRef * @param classRef
* @param versionableNode * the class reference
* @param versionProperties * @param versionableNode
* @param nodeDetails * the versionable node reference
* @param versionProperties
* the version properties
* @param nodeDetails
* the details of the node to be versioned
*/ */
public void onCreateVersion( public void onCreateVersion(
QName classRef, QName classRef,

View File

@@ -236,11 +236,12 @@ public interface LockService
/** /**
* Checks to see if the node is locked or not. Gets the user reference from the current * Checks to see if the node is locked or not. Gets the user reference from the current
* session. * session.
* <p>
* Throws a NodeLockedException based on the lock status of the lock, the user ref and the
* lock type.
* *
* @param nodeRef the node reference * @param nodeRef the node reference
*
* @throws NodeLockedException
* thrown if the node is locked. This is based on the lock status of the lock,
* the user ref and the lock type.
*/ */
@Auditable(key = Auditable.Key.ARG_0, parameters = {"nodeRef"}) @Auditable(key = Auditable.Key.ARG_0, parameters = {"nodeRef"})
public void checkForLock(NodeRef nodeRef); public void checkForLock(NodeRef nodeRef);