I tried create Tag[] using following code.
String[] tagsFromParent = ["global:test1", "global:test2"];
Tag[] tagsFromParentTransformed = Arrays.stream(tagsFromParent).map(s -> tagManager.resolve(s)).toArray(Tag[]::new);
I am getting following Tag[].
[null, null]
Please suggest something.
Or Is there any other way to create Tag[] from String[] ?
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @sangrampatil111 ,
The tag manager namespace should be /content/cq:tags.
Try to get a resource resolver from the system user with proper permission and check it again.
Please check whether the session from which you are creating TagManager object is having proper permission to access those tags. Please refer below snippet from Java Docs :
TagManager interface is generic, but there is a JCR-based reference implementation which can be obtained by the JcrTagManagerFactory
- all you need is an existing JCR Session
(what tags can be "seen" and which can be created depends on the user of that session)
The other way is by path but what you are trying should work.
Hi @sangrampatil111 ,
You are getting resolved Tag null because of java.lang.TypeNotPresentException (Stream provides the different type and Tag expects a different type).
Please find the alternate approach to resolve the String Tags :
//Get Resource Resolver with have proper permission
//Replce Tag String available in your AEM
String[] tags = {"learning:aem-sites", "learning:aem-assets", "learning:aem-analytics"};
TagManager tagManager = resourceResolver.adaptTo(TagManager.class);
Tag[] resolvedTags = new Tag[tags.length];
for(int count =0; count < tags.length; count++){
resolvedTags[count] = tagManager.resolve(tags[count]);
}
logger.info("Resolved Tags : {} ", Arrays.toString(resolvedTags) );
Logs :
Resolved Tags :[/content/cq:tags/learning/aem-sites, /content/cq:tags/learning/aem-assets, /content/cq:tags/learning/aem-analytics]
Hope this could help you!!!
Regards
Shiv
Thanks @Shiv_Prakash_Patel ,
I tried this. But it didn't worked.
I am getting namespace for Tagmanger as /content/cq:tags/facebook instead of /content/cq:tags/global.
I think becoz of this I am getting null values.
Do you have any idea about this ?
Hi @sangrampatil111 ,
The tag manager namespace should be /content/cq:tags.
Try to get a resource resolver from the system user with proper permission and check it again.
Thanks @Shiv_Prakash_Patel
Issue resolved now. It is due to permissions not given to service user on /content/cq:tags.
Views
Likes
Replies
Views
Likes
Replies