How to know type of node (content or folder) when I have NodeRef and NodeService in scope (Java API)

cancel
Showing results for 
Search instead for 
Did you mean: 
SG
Member II

How to know type of node (content or folder) when I have NodeRef and NodeService in scope (Java API)

I have a particular nodeRef variable and nodeService variable in scope inside the java code/method. How can I know the type of the nodeRef - whether it is of type contnet, or type folder.

It seems that nodeRef ( org.alfresco.service.cmr.repository.NodeRefSmiley Wink API does not offer any method like getType, or getNodeType.

With nodeRef in scope, how can I know whether the type is content or folder?

 

1 Reply
abhinavmishra14
Advanced

Re: How to know type of node (content or folder) when I have NodeRef and NodeService in scope (Java

Well you are looking into wrong class. You have nodeRef and nodeService. 

when you call nodeService.getType(nodeRef), you will get the type as QName. 

 

final QName nodeType = nodeService.getType(nodeRef);

Some examples:

If nodeRef is of content type (cm:content), you will get following result when you print the node type:

{http://www.alfresco.org/model/content/1.0}content 

If nodeRef is of content type (cm:folder), you will get following result when you print the node type:

{http://www.alfresco.org/model/content/1.0}folder

If nodeRef is of custom type (demo:whitePaper), you will get following result when you print the node type:

{http://www.xyz.com/model/demo/1.0}whitePaper (here http://www.xyz.com/model/demo/1.0 is namespace of your custom model)

Refer this javadoc to know more about QName : http://dev.alfresco.com/resource/AlfrescoOne/5.0/PublicAPI/org/alfresco/service/namespace/QName.html

 

 

Refer this javadoc for more detail on nodeService methods and getType method: 

http://dev.alfresco.com/resource/AlfrescoOne/5.0/PublicAPI/org/alfresco/service/cmr/repository/NodeS...

~Abhinav
(ACSCE, AWS SAA, Azure Admin)