<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: onDeleteNode and beforeDeleteNode fired when a new version is uploaded in Alfresco Forum</title>
    <link>https://connect.hyland.com/t5/alfresco-forum/ondeletenode-and-beforedeletenode-fired-when-a-new-version-is/m-p/81531#M25111</link>
    <description>&lt;P&gt;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.&lt;/P&gt;</description>
    <pubDate>Mon, 01 Jun 2020 13:26:45 GMT</pubDate>
    <dc:creator>afaust</dc:creator>
    <dc:date>2020-06-01T13:26:45Z</dc:date>
    <item>
      <title>onDeleteNode and beforeDeleteNode fired when a new version is uploaded</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/ondeletenode-and-beforedeletenode-fired-when-a-new-version-is/m-p/81530#M25110</link>
      <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Therefor I implemented a behaviour that should react on a version change (update external) and on the deletion (delete external) of a document.&lt;/P&gt;&lt;P&gt;But I realized that the policies &lt;STRONG&gt;beforeDeleteNode&lt;/STRONG&gt; and &lt;STRONG&gt;onDeleteNode&lt;/STRONG&gt; are both triggered when a new version is uploaded.&lt;/P&gt;&lt;P&gt;For me this makes no sense because the Node is &lt;STRONG&gt;NOT&lt;/STRONG&gt; deleted, only a new version is created for an existing Node.&lt;/P&gt;&lt;P&gt;I consider this as a bug, because the Node document&amp;nbsp; is only replaced with another Node. It keeps the id, the properties etc...&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;This breakes the concept of CRUD.&lt;/P&gt;&lt;P&gt;Does anyone know which event to react on, when a node is indeed deleted (or archived) from the repository?&lt;/P&gt;</description>
      <pubDate>Sun, 31 May 2020 18:46:09 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/ondeletenode-and-beforedeletenode-fired-when-a-new-version-is/m-p/81530#M25110</guid>
      <dc:creator>akreienbring</dc:creator>
      <dc:date>2020-05-31T18:46:09Z</dc:date>
    </item>
    <item>
      <title>Re: onDeleteNode and beforeDeleteNode fired when a new version is uploaded</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/ondeletenode-and-beforedeletenode-fired-when-a-new-version-is/m-p/81531#M25111</link>
      <description>&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jun 2020 13:26:45 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/ondeletenode-and-beforedeletenode-fired-when-a-new-version-is/m-p/81531#M25111</guid>
      <dc:creator>afaust</dc:creator>
      <dc:date>2020-06-01T13:26:45Z</dc:date>
    </item>
    <item>
      <title>Re: onDeleteNode and beforeDeleteNode fired when a new version is uploaded</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/ondeletenode-and-beforedeletenode-fired-when-a-new-version-is/m-p/81532#M25112</link>
      <description>&lt;P&gt;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:&lt;/P&gt;&lt;P&gt;In the behaviour I've implemented:&lt;/P&gt;&lt;PRE&gt;	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;
		}
	}&lt;/PRE&gt;&lt;P&gt;Note that this does NOT work in the onDeleteNode event. When onDeleteNode is fired the aspect is not present anymore.&lt;/P&gt;&lt;P&gt;I hope that this works in all cases the beforeDeleteNode is fired.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jun 2020 17:13:11 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/ondeletenode-and-beforedeletenode-fired-when-a-new-version-is/m-p/81532#M25112</guid>
      <dc:creator>akreienbring</dc:creator>
      <dc:date>2020-06-01T17:13:11Z</dc:date>
    </item>
    <item>
      <title>Re: onDeleteNode and beforeDeleteNode fired when a new version is uploaded</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/ondeletenode-and-beforedeletenode-fired-when-a-new-version-is/m-p/81533#M25113</link>
      <description>&lt;P&gt;&lt;STRONG&gt;EDIT&lt;/STRONG&gt; : issue was solved by triggering the event on FIRST_EVENT rather than TRANSACTION_COMMIT. Apparently when beforeDeleteNode is at TRANSACTION_COMMIT stage the node is already deleted.&lt;/P&gt;&lt;P&gt;Hello there,&lt;/P&gt;&lt;P&gt;In which version of Alfresco did this code run?&lt;/P&gt;&lt;P&gt;Currently in Alfresco 6, I have some InvalidNodeRefException (Node does not exist) in a beforeMoveNode event callback.&lt;/P&gt;&lt;P&gt;The callback is registered without fancyness :&lt;/P&gt;&lt;PRE&gt;        eventManager.bindClassBehaviour(
            NodeServicePolicies.BeforeDeleteNodePolicy.QNAME,
            ContentModel.TYPE_CONTENT,
            new JavaBehaviour(this, "beforeDeleteDocument",
                NotificationFrequency.TRANSACTION_COMMIT
            ));&lt;/PRE&gt;&lt;P&gt;and then we have your implementation (thanks to you) :&lt;/P&gt;&lt;PRE&gt;    private boolean hasWorkingCopyAspect(NodeRef nodeRef) {	
		if (nodeService.hasAspect(nodeRef, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "workingcopy"))) {
			return true;
		}
		return false;
	}

    public void beforeDeleteDocument(NodeRef nodeRef) throws WikiException {
        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
            return;
			
		};
        String nodeName = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);&lt;/PRE&gt;&lt;P&gt;and so on and so on.&lt;/P&gt;&lt;P&gt;I have the InvalidNodeRefException in the nodeService.hasAspect call. If I comment it, then I have the InvalidNodeRefException in the nodeService.getProperty call.&lt;/P&gt;&lt;P&gt;In all other implemented behaviours of the policy the nodeService works like a charm.&lt;/P&gt;&lt;P&gt;It's as if the node was already deleted at beforeDeleteNode call time, which doesn't make any sense to me...&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jan 2023 18:47:26 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/ondeletenode-and-beforedeletenode-fired-when-a-new-version-is/m-p/81533#M25113</guid>
      <dc:creator>badawiraphael</dc:creator>
      <dc:date>2023-01-17T18:47:26Z</dc:date>
    </item>
  </channel>
</rss>

