0
votes

I am trying to create an auto-generated GUID property on all cq:PageContent nodes. This will be similar to the jcr:uuid property, but will be persisted with content promotion/replication/package installs (whereas the jcr:uuid for a content item changes between different environments).

I am trying to determine how AEM/JCR generates the jcr:uuid property on node creation. The CND defining the property is:

[mix:referenceable]
  mixin
  - jcr:uuid (string) mandatory autocreated protected initialize

I've tried defining my GUID property in a similar manor, specifying the autocreated and initialize attributes, but this did not result in auto-generation of the property.

Could anybody point me to the source of the jcr:uuid's generation?


As an aside, I asked a related question on the Adobe Community Forum: http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manager.topic.5_ciot.html/forum__bnxr-i_am_tryingtocreat.html

1
Can't you just create a hash from the path?Thomas
The question isn't about how to generate an ID, but rather how the jcr:uuid is created; how the generation of that ID is invoked. I am trying to understand if that ID is generated automagically by the JCR (and if so, how to do so for other properties), or if there is an event handler being invoked.Dave Hughes
I found this post. maybe it helps you: jackrabbit.510166.n4.nabble.com/… In short it depends on the JCR implementation in the case of CQ this is Jackrabbit and there you should be able to get the source to see how it is done.Thomas

1 Answers

2
votes

You don't mention which version of AEM (so whether you're dealing with Jackrabbit or Oak), but the mechanism turns out to be basically the same.

When assigning a default value, there are a few hard-coded system property names that get special treatment (jcr:uuid being one of them). If the name of the property being assigned a default value doesn't match any of the special cases, it falls back the static list of default values from the property definition (e.g. listed in the CND file).

In summary, it looks like you cannot piggy-back on this mechanism to assign your own dynamic default value for an arbitrary property. You would need to implement your own event listener or something.


Jackrabbit: See the implementation of setDefaultValues and computeSystemGeneratedPropertyValues

Oak: See the implementation of TreeUtil autoCreateProperty