cancel
Showing results for 
Search instead for 
Did you mean: 

Checking node existence on behaviour execution: nodeService.exists(nodeRef) vs status.isDeleted()

eureka
Champ in-the-making
Champ in-the-making
Hi all,

I've tried to search for this topic in the forum with no luck, so forgive me if it has already been asked and please point me to the post/s where I can find any information that could help me.


I was having this doubt: when creating a Behaviour bound to onUpdateNodePolicy is it safer to check for the existence of the current node using NodeService


if(nodeService.exists(nodeRef))


or Status


Status status = nodeService.getNodeStatus(nodeRef);
if (status != null && !status.isDeleted()) {

}


Thank in advance to anyone who might want to share his/her opinion about this subject.

Angelo
3 REPLIES 3

mrogers
Star Contributor
Star Contributor
You shouldn't need to worry about being called via onUpdateNode for a deleted node. Unless there's something wierd going on like the node being deleted by other policies.
I suspect you want the exists call withing a policy callback.

The isStatus call allows you to distinguish between a node that has never existed and one that has been deleted.  Its main use is for async tracking.

Hello,

I would like to ask why one would need to use exists() and isDeleted() <strong>together</strong> in one condition like in the case of <a href="https://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/COMMUNITYTAGS/V5.0.d/root/modules/wcmqu...">SiteHelper.java</a> which contains this code:

<java>
// ALF-18325 fix, check that site is not null, exists, is not deleted and is not being deleted
if (siteInfo != null && nodeService.exists(shareSiteId) && !nodeService.getNodeStatus(shareSiteId).isDeleted()
        && !nodeService.hasAspect(shareSiteId, ContentModel.ASPECT_PENDING_DELETE))

</java>

From the various implementations of the NodeService methods, one can see that exists() in fact includes the logic from getNodeStatus().isDeleted() and in the case of AVMNodeService the getNodeStatus() even calls exists() to find out the deleted status! So as you can see, using these two functions <strong>together</strong> seems pretty useless. Am I right, or did I overlook something?

Or do you think guys I should create a separate forum thread for this? The question itself is hopefully clear.