Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

tagManager resolve not working.

Avatar

Level 2

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
Level 4

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.

 

View solution in original post

5 Replies

Avatar

Level 7

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

Level 4

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

Avatar

Level 2

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
Level 4

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.

 

Avatar

Level 2

Thanks @Shiv_Prakash_Patel 

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