Expand my Community achievements bar.

AEM Tagging - Not pulling results with TagManager.find

Avatar

Level 3

Sorry, I really hope that this is not too basic of a question.  That said, please forgive the basic-ness of the question as this is really my first foray into tagging.  My local environment is a Windows environment running AEM 6.1, but I don't think I have gotten around to installing SP1 there yet.  Alternatively, my Dev environment is on Linux, AEM 6.1 and we do have SP1 installed on there.

So I have a component built on tagging that works just fine in my local environment (both Author and Publisher) but when I promoted it to our Dev environment it is not pulling the results with TagManager.find in Publisher only (but it does work in Author).  When I first tested on Publish in my local environment it didn't work there either at first, until I found https://docs.adobe.com/docs/en/aem/6-1/develop/tags/framework.html and added cq:Taggable to the Page Component, at which point it worked fine.  Based on the displays I have setup in the code, TagManager.find is returning null (and not throwing any sort of error).  I am doing a ResourceResolver.adaptTo to create the TagManager.  Please see attached screen shots.

Thanks in advance for your help!

Brad W

14 Replies

Avatar

Level 10

Have you replicated tags which are created in Dev author to Dev publish?

Avatar

Level 3

Good thought, but it auto-promoted just that tag when I promoted either page or the tagged component.

Avatar

Level 10

Are you saying ;

You have authored tags in author and when viewing same page in publish after activation you are getting null error

and you have replicated tags to publish instance

Let me know if my understanding is correct on this....

Avatar

Level 3

Yes, the screen shot above is showing that the tag has been promoted to the publish environment.  When I do tagmanager.find(rootDirectory, tagID) it is returning null.  I have it pointing to the correct directory and both the find and the pages I am trying to pull are using that tag that has been promoted to publish.  Is there some sort of config or something that might be messing with this?

Thanks.

Brad.

Avatar

Level 10

Thanks for explanation

can you share code snippet you are using....

Avatar

Level 3
    TagManager tagManager = request.getResourceResolver().adaptTo(TagManager.class); Optional<String[]> tagArrayOptional = getOptionsTags(); if (request.getWCMMode() != WCMMode.EDIT) { RangeIterator<Resource> resourceRangeIterator = null; if (tagArrayOptional.isPresent()) { LOG.info(CONTROL_NAME + "Options Root: " + optionsRoot); String[] tagArray = tagArrayOptional.get(); String tagValues = StringUtils.EMPTY; for (int ctr = 0; ctr < tagArray.length; ctr++) { tagValues += tagArray[ctr] + ", "; } LOG.info(CONTROL_NAME + "Tags: " + tagValues); resourceRangeIterator = tagManager.find(optionsRoot, tagArray); } if (resourceRangeIterator != null) { LOG.info(CONTROL_NAME + "Resources Found: " + String.valueOf(resourceRangeIterator.getSize())); optionList = getResourceListing(resourceRangeIterator, RESOURCE_TYPE_TO_PULL); if ((optionList != null) && (optionList.size() > 0)) { setFirstImageTextPropertiesFromFirstChild(optionList.get(0)); } } else { LOG.info(CONTROL_NAME + "No Resources Found"); } }

In Author it is obviously hitting the Resources Found message and in Publish it is hitting the No Resources Found message.

Avatar

Level 4

Can you provide the code snippet for the getOptionalTags() method, I think that's the method of interest here since that is where the tags are retrieved and built.

Avatar

Level 3

Naveen - I am including it below, but after what I came across yesterday afternoon, I don't believe that this is the problem (not to mention, this is returning the one tag that is in the field).

public Optional<String[]> getOptionsTags() { return get("cq:tags", String[].class); }

All of that said, I think the key thing at this point seems to be the cq:Taggable declaration and somehow getting it to apply to the new pages that have global-web/components/page/optionPage as their resourceType.  When I discovered yesterday that this wasn't working locally like I thought it was, I went and manually applied that property to the jcr:content node for the page I was trying to get to pull in.  When I did that, not only did it pull in, but all of the other optionPage's in the same directory also pulled into the component.  So, as a curiosity, I removed the cq:Taggable property and (after I restarted my local Publisher) it would not pull in again.  So, somehow, I need to make it so when someone selects the optionPage as the type of page they are trying to create that the cq:Taggable node = true property gets applied to the jcr:content node that is created.  Any suggestions on how to do that?

Avatar

Level 9

Is it similar to this quesiton "Tag component not working properly in Publish instance"?

Are you using AEM 6.1?  Have you set the permissions on publish?

- JK

Avatar

Level 3

JK - Based on my initial read of your provided link I am pretty sure we haven't done this.  I will give it a try and come back and let you know.  Thanks!

Avatar

Level 3

Bad news, in this case it does not seem to have helped.  Based on the screen shot provided from our Operations dept it does appear that the tag is readable by all in that publish environment now (admittedly it was not before). 

Avatar

Level 3

JK - just FYI, based on what we are seeing this still isn't working.  Sorry for the duplicate post, but I am wondering if you did not see my last response because I "replied to myself"?

Thanks.

Avatar

Level 3

Hey all, Decided I would revisit this and discovered that it is not working on my local Publish environment like I thought it was.  I am revisiting the changes that I swear made it work to try and reproduce the situation where it was working.

Avatar

Level 9

Hi - I write documentation for the Communities capability.

See the information I was given for Tagging Enablement Resources.

You might open a support ticket if you continue to have problems.

- JK