onDeleteNode and beforeDeleteNode fired when a new version is uploaded

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Active Member

onDeleteNode and beforeDeleteNode fired when a new version is uploaded

I'm developing some kind of CRUD application that needs to create, update and delete an external repository when content (a special type of document) changes in Alfresco.

Therefor I implemented a behaviour that should react on a version change (update external) and on the deletion (delete external) of a document.

But I realized that the policies beforeDeleteNode and onDeleteNode are both triggered when a new version is uploaded.

For me this makes no sense because the Node is NOT deleted, only a new version is created for an existing Node.

I consider this as a bug, because the Node document  is only replaced with another Node. It keeps the id, the properties etc...

On the other hand I think there's no need to fire these events on a version change. Because the VersionServicePolicies is sufficient to react on it.

This breakes the concept of CRUD.

Does anyone know which event to react on, when a node is indeed deleted (or archived) from the repository?

 

2 Replies
Highlighted
Master

Re: onDeleteNode and beforeDeleteNode fired when a new version is uploaded

This is not a bug. A new node is created and deleted - the temporary working copy on which all changes are applied before those are committed to the primary node. This is a conscious design of the Share upload web script, and can happen in other contexts as well as working copies (via the CheckOutCheckInService) are a core concept in Alfresco. You absolutely have to check for the presence of a working copy aspect in any behaviours where you only want to act on "real" nodes.

Active Member

Re: onDeleteNode and beforeDeleteNode fired when a new version is uploaded

Thanks for the hint with the working copy aspect. For others who want to do something when a node is finally deleted, here's how I solved it for now:

In the behaviour I've implemented:

	public void beforeDeleteNode(NodeRef nodeRef) {
		if (logger.isDebugEnabled()) logger.debug("Inside beforeDeleteNode. Calling disable-web-flag");
		
		if(!hasWorkingCopyAspect(nodeRef)){
			//if a node has the working copy aspect then this event was triggered even thought
			//the NODE / Document is NOT finally deleted. For example if a new version is uploaded or was 
			//checked out / in
			
			Action action = actionService.createAction("[whatever-must-be-deletet]");
			actionService.executeAction(action, nodeRef);
			
		};
	}

	private boolean hasWorkingCopyAspect(NodeRef nodeRef) {
		// check the node for the presence of the working copy aspect
		if (logger.isDebugEnabled()) logger.debug("Node exists = " + nodeService.exists(nodeRef));
		
		if (nodeService.hasAspect(nodeRef, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,"workingcopy"))) {
			if (logger.isDebugEnabled()) logger.debug("Node has the working copy aspect.");
			
			return true;
		} else {
			if (logger.isDebugEnabled()) logger.debug("Node doesn't have the working copy aspect.");
			return false;
		}
	}

Note that this does NOT work in the onDeleteNode event. When onDeleteNode is fired the aspect is not present anymore.

I hope that this works in all cases the beforeDeleteNode is fired.