tagManager resolve not working. | Community
Skip to main content
Level 3
August 3, 2022
Solved

tagManager resolve not working.

  • August 3, 2022
  • 2 replies
  • 1346 views

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[] ? 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Shiv_Prakash_Patel

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.

 

2 replies

Sachin_Arora_
Community Advisor
Community Advisor
August 3, 2022

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.

 

Link : https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/index.html?com/day/cq/tagging/TagManager.html

 

 

 

Shiv_Prakash_Patel
Community Advisor
Community Advisor
August 3, 2022

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

Shiv Prakash
Level 3
August 4, 2022

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 ?

 

Shiv_Prakash_Patel
Community Advisor
Shiv_Prakash_PatelCommunity AdvisorAccepted solution
Community Advisor
August 4, 2022

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.

 

Shiv Prakash