cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot get node content using onCreateNode behavior

abraxas
Champ in-the-making
Champ in-the-making
I've created a custom Java behavior bound to the onCreateNode event that works just fine, except
that I can't retrieve the content from the node using:

ContentReader cReader = contentService.getReader(car.getChildRef(), nodeService.getType(car.getChildRef()));
String content = cReader.getContentString();
//car is the retrieved ChildAssociationRef 

I just get an nullPointerException on the first mentioned line when i run the code while I'm able to retrieve other properties without problems.
I'm interested if this is a known issue and if there is a workaround for retrieving the content node.

The content in this case is a string contained in a comment post node. My suspicion is that ContentReader can't retrieve the content node because
the node referenced is not yet available (not written) to alfresco at that moment.

If you need more information, please let me know.
Thanks.
2 REPLIES 2

fiferyan
Champ in-the-making
Champ in-the-making
It's been a while since you asked this but I see it hasn't been answered yet.

I had the same problem using a javascript behaviour. My solution was to use the onContentChanged behaviour instead.  The signature is slightly different but it gets you access to the content and tells you if it's new content so you can simulate onCreateContent. Not a complete answer but hopefully it points you in the right direction.

larsg_
Champ in-the-making
Champ in-the-making
Hi,

just as an idea: I had a similar problem (the onCreateNode methode was called, but requesting the properties of the new node doesn't get me all of the expected properties). As soon as I specified the NotificationFrequency to be TRANSACTION_COMMIT everything is working fine:


JavaBehaviour onCreateNodeBehaviour = new JavaBehaviour(this, "onCreateNode", NotificationFrequency.TRANSACTION_COMMIT);
policyComponent.bindClassBehaviour(OnCreateNodePolicy.QNAME, qNameOfMyType, onCreateNodeBehaviour);


The reason seems to be, that the new node ist created (even with specialised type) which causes the event, and that later the additional properties are added. When you register to the onUpdateProperties event with default NotificationFrequency (= EVERY_EVENT) this event is raised twice. The first time the node contains only a few properties. The second time the others are present, too.