Reputation: 5165
I want to check the names of the labels in the page on which the macro is enabled and its children as well. Is this possible using a custom macro? I followed this tutorial: https://developer.atlassian.com/server/framework/atlassian-sdk/create-a-confluence-hello-world-macro/
And looked at some other documentation but couldn't verify.
Upvotes: 0
Views: 919
Reputation: 326
The Page class gives you access to both the page's labels (via getLabels()
) and ALL the page's children (via getChildren()
, but note no permission checking is done). I don't have a Java dev environment right now, but I was able to display the labels for the current page and its children in a user macro (via the $content
variable):
<h2>Labels</h2>
<code>$content.labels</code>
<h2>Children's Labels</h2>
<ul>
#foreach($child in $content.children)
<li> <code> $child.labels </code> </li>
#end
</ul>
Upvotes: 1
Reputation: 450
There are two ways I can think of -
1) Custom Plugin
I am covering high-level detail of how to get the desired result. You may face a couple of errors when actually trying to do this. So GOOGLE is your best friend.
First, you will have to retrieve all the pages with you macro on it with SQL query
SELECT c.contentid, c.contenttype, c.title, s.spacekey
FROM CONTENT c
JOIN BODYCONTENT bc
ON c.contentid = bc.contentid
JOIN SPACES s
ON c.spaceid = s.spaceid
WHERE c.prevver IS NULL
AND c.contenttype IN ('PAGE', 'BLOGPOST')
AND bc.body LIKE '%ac:name="<macro_name>"%';
Then get all the pages with the label using something like :
SELECT * FROM CONTENT
WHERE CONTENTID IN (SELECT CONTENTID FROM CONTENT_LABEL
WHERE LABELID IN (SELECT LABELID FROM LABEL
WHERE NAME='<label name>'));
Join result of both of them together using content Id or you could also make one call to get already joined output.
You have the pages.
You can get their children using another query like
SELECT c.contentid, c.title FROM CONFANCESTORS a JOIN CONTENT c ON a.descendentid = c.contentid WHERE a.ancestorid = '<parent_page_id>'
2) Rest Calls
It is a little complicated way, I wouldn't recommend but the steps would similar to custom plugin.
Upvotes: 0