<?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 Create new version with Behaviours/Policies in Alfresco Archive</title>
    <link>https://connect.hyland.com/t5/alfresco-archive/create-new-version-with-behaviours-policies/m-p/296997#M250127</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a rather simple behaviour/policy implementation. When an aspect "signedDateAspect" is added to a document, check and set the value for the property "signedDate". The code (relevant part) is below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;public class SignedDateAspectPolicy implements NodeServicePolicies.OnAddAspectPolicy {&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;public void init() {&lt;/P&gt;&lt;P&gt;&amp;nbsp; this.onAddAspectBehavior = new JavaBehaviour(this, "onAddAspect", NotificationFrequency.TRANSACTION_COMMIT);&lt;/P&gt;&lt;P&gt;&amp;nbsp; this.policyComponent.bindClassBehaviour(NodeServicePolicies.OnAddAspectPolicy.QNAME,&lt;BR /&gt; MycContentModel.ASPECT_SIGNED_DATE, this.onAddAspectBehavior);&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;@Override&lt;BR /&gt; public void onAddAspect(NodeRef nodeRef, QName aspectTypeQName) {&lt;BR /&gt;&amp;nbsp; Serializable propSignedDate = this.nodeService.getProperty(nodeRef, MycContentModel.PROP_SIGNED_DATE);&lt;/P&gt;&lt;P&gt;&amp;nbsp; if (propSignedDate == null) {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; Date propModified = (Date) this.nodeService.getProperty(nodeRef, ContentModel.PROP_MODIFIED);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; this.nodeService.setProperty(nodeRef, MycContentModel.PROP_SIGNED_DATE, propModified);&lt;BR /&gt;&amp;nbsp; }&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It works fine until a new version of the document is uploaded. Steps to replicate:&lt;/P&gt;&lt;P&gt;1. Upload a document - pass&lt;/P&gt;&lt;P&gt;2. Add the aspect - pass&lt;/P&gt;&lt;P&gt;3. Upload a new version - fail&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The error in log is&lt;/P&gt;&lt;P&gt;Caused by: org.alfresco.service.cmr.repository.InvalidNodeRefException: Node does not exist: workspace://SpacesStore/e3a32cce-de90-4957-b026-7ef683e8a713 (status&lt;img id="smileyfrustrated" class="emoticon emoticon-smileyfrustrated" src="https://connect.hyland.com/i/smilies/16x16_smiley-frustrated.png" alt="Smiley Frustrated" title="Smiley Frustrated" /&gt;tatus[id=12279changeTxnId=3cc18e2f-c628-40cd-9f71-640a86de9d39, dbTxnId=4550, deleted=true])&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I had to add a check at the beginning of onAddAspect method.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if (!this.nodeService.exists(nodeRef)) {&lt;BR /&gt;&amp;nbsp; return;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What is the node "&lt;SPAN&gt;workspace://SpacesStore/e3a32cce-de90-4957-b026-7ef683e8a713" that is created in this process? Why doesn't it exist (did it get deleted)? Could someone explain the inner working of how a new version is created in Alfresco? Thanks.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 16 Dec 2016 19:50:54 GMT</pubDate>
    <dc:creator>zhihailiu</dc:creator>
    <dc:date>2016-12-16T19:50:54Z</dc:date>
    <item>
      <title>Create new version with Behaviours/Policies</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/create-new-version-with-behaviours-policies/m-p/296997#M250127</link>
      <description>I have a rather simple behaviour/policy implementation. When an aspect "signedDateAspect" is added to a document, check and set the value for the property "signedDate". The code (relevant part) is below.public class SignedDateAspectPolicy implements NodeServicePolicies.OnAddAspectPolicy {public void</description>
      <pubDate>Fri, 16 Dec 2016 19:50:54 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/create-new-version-with-behaviours-policies/m-p/296997#M250127</guid>
      <dc:creator>zhihailiu</dc:creator>
      <dc:date>2016-12-16T19:50:54Z</dc:date>
    </item>
    <item>
      <title>Re: Create new version with Behaviours/Policies</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/create-new-version-with-behaviours-policies/m-p/296998#M250128</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Forget to specify that it is tested on Alfresco 5.0&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 16 Dec 2016 19:57:09 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/create-new-version-with-behaviours-policies/m-p/296998#M250128</guid>
      <dc:creator>zhihailiu</dc:creator>
      <dc:date>2016-12-16T19:57:09Z</dc:date>
    </item>
    <item>
      <title>Re: Create new version with Behaviours/Policies</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/create-new-version-with-behaviours-policies/m-p/296999#M250129</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Your issue likely is related to the fact that you are using TRANSACTION_COMMIT for binding the policy. Unfortunately I see that quite a lot in blog posts or other community examples without people understanding implications / side effects of it. During "Upload New Version" a temporary node will be created (a working copy since "Upload New Version" consists of a check-out/check-in cycle) which will get deleted before the operation is complete. This node will cause the behaviour to be triggered, but since you specified TRANSACTION_COMMIT it will only be called at the end of the transaction after the temporary node has already been deleted again.&lt;/P&gt;&lt;P&gt;This is not related to how versions are created in general - it is just a specific of the "Upload New Version" UI action, which actually simulates three user actions (check-out, edit the working copy, check-in) to ensure some behavioural consistency to different ways a user could interact with the system and trigger these actions invidiually.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 18 Dec 2016 15:03:30 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/create-new-version-with-behaviours-policies/m-p/296999#M250129</guid>
      <dc:creator>afaust</dc:creator>
      <dc:date>2016-12-18T15:03:30Z</dc:date>
    </item>
    <item>
      <title>Re: Create new version with Behaviours/Policies</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/create-new-version-with-behaviours-policies/m-p/297000#M250130</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Axel,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your response. That clearly explained check in/out in "Upload New Version" and resulted "node not found". Extremely helpful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As for the fix, do you think the "return if not exists" approach is acceptable? Or it should switch to other binding such as EVERY_EVENT?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 18 Dec 2016 16:47:50 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/create-new-version-with-behaviours-policies/m-p/297000#M250130</guid>
      <dc:creator>zhihailiu</dc:creator>
      <dc:date>2016-12-18T16:47:50Z</dc:date>
    </item>
    <item>
      <title>Re: Create new version with Behaviours/Policies</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/create-new-version-with-behaviours-policies/m-p/297001#M250131</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I prefer to use the EVERY_EVENT notification frequency in almost all instances. But that does not absolve the programmer from doing the necessary pre-condition checks, and "return if not exists" is one of the proper checks to perform for TRANSACTION_COMMIT. Another would be "is the node part of workspace://SpacesStore" by comparing the StoreRef of the NodeRef against the constant in StoreRef-class.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 18 Dec 2016 20:18:18 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/create-new-version-with-behaviours-policies/m-p/297001#M250131</guid>
      <dc:creator>afaust</dc:creator>
      <dc:date>2016-12-18T20:18:18Z</dc:date>
    </item>
    <item>
      <title>Re: Create new version with Behaviours/Policies</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/create-new-version-with-behaviours-policies/m-p/297002#M250132</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Dec 2016 13:58:57 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/create-new-version-with-behaviours-policies/m-p/297002#M250132</guid>
      <dc:creator>zhihailiu</dc:creator>
      <dc:date>2016-12-19T13:58:57Z</dc:date>
    </item>
  </channel>
</rss>

