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
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

6.4 tagmanagerobject.resolve(tagid) returning null

AdobeID24
Level 6
Level 6

 

tagmanagerobject.resolve(tagid) return ing null everytime.... I m using 6.4.1

 

Code is written inside active method and in class we are using wcmusepojo by extending it..... 

 

We got tag manager as getresourceresolver. Adapto(TagMAnager) 

Other points which I strict verified 

 

I m running my code in local...as admin...admin has all the access.......Where all tags are present.... 

 

Tagamanger obejvt is not null.... 

 

Tag I'd format is proper... Namesapce:fruits/apple kind...... 

1 Accepted Solution
vanegi
Correct answer by
Employee
Employee

As you know, tags are stored in the /etc paths in your JCR. When you logged out of  publisher as an admin, the resolver would NOT be able to access the tags object in /etc. Hence, it is returning nulls.

 

To solve this, you can create a new OSGI service like below:

public Class TagServiceImpl implements TagService {
 
  ResourceResolverFactory resolverFactory;
 
  public void init() {
    Map<String, Object> params = new HashMap<>();
    params.put(ResourceResolverFactory.SUBSERVICE, "companyServiceThread");
    ResourceResolver resourceResolver = resourceResolverFactory.getServiceResourceResolver(params);
  }
 
  public void kill() {
    resolver = null;
  }
  public Tag getTag(String tagID) {
 
    Tag myTag = resourceResolver.adaptTo(TagManager.class).resolve(tagID); //Now  works!!
    return myTag;
  }
 
 
This service-user has been given the appropriate read/write privileges to required paths. Hence, the tag (myTag) can be successfully resolved. 

View solution in original post

1 Reply
vanegi
Correct answer by
Employee
Employee

As you know, tags are stored in the /etc paths in your JCR. When you logged out of  publisher as an admin, the resolver would NOT be able to access the tags object in /etc. Hence, it is returning nulls.

 

To solve this, you can create a new OSGI service like below:

public Class TagServiceImpl implements TagService {
 
  ResourceResolverFactory resolverFactory;
 
  public void init() {
    Map<String, Object> params = new HashMap<>();
    params.put(ResourceResolverFactory.SUBSERVICE, "companyServiceThread");
    ResourceResolver resourceResolver = resourceResolverFactory.getServiceResourceResolver(params);
  }
 
  public void kill() {
    resolver = null;
  }
  public Tag getTag(String tagID) {
 
    Tag myTag = resourceResolver.adaptTo(TagManager.class).resolve(tagID); //Now  works!!
    return myTag;
  }
 
 
This service-user has been given the appropriate read/write privileges to required paths. Hence, the tag (myTag) can be successfully resolved. 

View solution in original post