Hello,
I am trying to get a list of all labels and the number of times they were used for each user. The LabelManager offers some methods that seem promising, but when testing them, they did not return the labels I just created.
I tried the following:
import java.util.List; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.core.Response; import com.atlassian.confluence.labels.Label; import com.atlassian.confluence.labels.LabelManager; import com.atlassian.confluence.user.AuthenticatedUserThreadLocal; import com.atlassian.confluence.user.ConfluenceUser; import com.google.common.collect.Lists; @Path("/labeltest") public class TestResource { LabelManager labelManager; public TestResource(final LabelManager labelManager) { this.labelManager = labelManager; } @GET public Response get() { final ConfluenceUser user = AuthenticatedUserThreadLocal.get(); final List<Label> labels = labelManager.getUsersLabels(user.getName()); final List<String> labelNames = Lists.newArrayList(); for (final Label label : labels) { labelNames.add(label.getName()); } return Response.ok(labelNames).build(); } }
But this only returns
[ "favourite" ]
The labels I just added to some content are not shown.
Do you have any suggestion how I can get a List of all labels created by a user and the number of times they are user by her?
Thank you,
Robert
Community moderators have prevented the ability to post new answers.
I'm not sure you can - the call you are using pulls back the user's personal labels, not the global labels they may have happened to create. Personal labels are not visible to other users.
I've a strong suspicion that global labels don't record the creator or date, just that they're on pages. I think you'd have to trawl the page history records for label changes to get what you're looking for (and I'm not sure even that would do it)
As far as I can tell it looks like that. I guess I need a new approach.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Robert,
As far as I know, getUsersLabels only returns personal labels, not global labels. You can use labellings to figure out which user attached which label:
https://docs.atlassian.com/confluence/latest/com/atlassian/confluence/labels/Labelling.html
I found a function to get all user labeled content, but not necessarily the labels themselves (findAllUserLabelledContent):
My guess is that you could find all content labeled by a user, then use getLabelings, then step through all labellings until you find the user that matches the user you are looking for.
But maybe there is a better way that someone else is aware of...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I already tried using the LabelDao directly, but if I add the component-import, my plugin refuses to start.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.