Confluence Java API for dealing with space links is not working

Deleted user May 4, 2018

There is a method, MutatingEntityLinkService.getEntityLinksForKey(), which is supposed to return a list of the set entity links for a given Confluence space.

I call it this way:

this.mutatingEntityLinkService.getEntityLinksForKey(confluenceSpaceKey,
                ConfluenceSpaceEntityType.class);

Where confluenceSpaceKey is the key of a Confluence space that has got an entity link with JIRA (you can set it through space tools > integrations > application links). I am sure that the aforementioned application link exists within my space. Believe me. It exists, it is true and it is never going to be false. It exists. The problem is that the method used to work before and it returned the entity link, but now it only returns an empty list. I haven't screwed with anything. It stopped working on its own without any reason. It is really driving me nuts. Could someone out there figure out why is this such strange thing happening to me? I am very worried about it.

 

Thank you.

1 answer

0 votes
Deleted user May 7, 2018

Well my problem was that I was inside of an scheduled service and there you don't have a user session so you don't have permissions for getting anything. It is just as easy as executing this inside of the service before you do queries that need permissions, replacing the "admin" name by the name of a user that has got the required permissions:

ConfluenceUser user = userAccessor.getUserByName("admin");
AuthenticatedUserThreadLocal.set(user);

 I haven't found any documentation about how to do this, and this solution is the result of a very long time of trial and error, so I write this hoping it helps somebody at some time.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events