Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

tagManager resolve not working.

Avatar

Level 4

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @sangrampatil111 ,

The tag manager namespace should be /content/cq:tags.

tagNameSpace.png

Try to get a resource resolver from the system user with proper permission and check it again.

 

Shiv Prakash

View solution in original post

5 Replies

Avatar

Community Advisor

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.

sachinarora_0-1659523188526.png

 

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

 

 

 

Avatar

Community Advisor

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

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 ?

 

Avatar

Correct answer by
Community Advisor

Hi @sangrampatil111 ,

The tag manager namespace should be /content/cq:tags.

tagNameSpace.png

Try to get a resource resolver from the system user with proper permission and check it again.

 

Shiv Prakash

Thanks @Shiv_Prakash_Patel 

Issue resolved now. It is due to permissions not given to service user on /content/cq:tags.