Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to create default labels for a content template in a confluence space blueprint?

PJ September 15, 2015

Hello,

we have developed some space blueprints. Each blueprint has some children pages. We want to set labels on these pages (automatically when the space and the corresponding pages are created).

Anyone knows how? Or if at all possible? I tried index-key (<space-blueprint key="xx" i18n-name-key="confluence.blueprints.space.xx" category="yy" index-key="testlabel">) but it doesn't seem to have any effect whatsoever.

Thanks for any tips in advance! smile

6 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
J January 27, 2016

Just adding some code to @Robert Reiner [smartics] solution. 

One can really use the event listeners to achieve this: 

 

@EventListener
public void pageCreatedEvent(PageCreateEvent event) {
    log.debug("Page created event:%s", event.getPage().getTitle());
 
    if (event.getPage().getTitle().equalsIgnoreCase("&lt;put-in-your-page-title&gt;")) {
        labelManager.addLabel((Labelable) event.getPage(), new Label("&lt;put-in-your-label"));
    }
}

 

The labelManager is injected automatically. Just put a field in your event class like this: 

public class MyAnnotatedEventListener implements InitializingBean, DisposableBean {

	private static final Logger log = LoggerFactory.getLogger(MyAnnotatedEventListener.class);

	protected EventPublisher eventPublisher;
	protected PageManager pageManager;
	protected ThemeManager themeManager;
	protected LabelManager labelManager;
 
...

 

And register you event class in atlassian-config.xml:

&lt;component-import key="eventPublisher" interface="com.atlassian.event.api.EventPublisher"/&gt;

&lt;component-import key="themeManager" interface="com.atlassian.confluence.themes.ThemeManager"/&gt;

&lt;component-import key="labelManager" interface="com.atlassian.confluence.labels.LabelManager"/&gt;

&lt;component name="My Annotated Event Listener" key="annotatedEventListener" class="de.my.package.MyAnnotatedEventListener"/&gt;

  

0 votes
PJ January 26, 2016

Great! Thanks Jens!

0 votes
J January 26, 2016

I created a suggestion ticket for this: https://jira.atlassian.com/browse/CONF-40591

0 votes
PJ September 29, 2015

Thanks Robert! Should I put the method (onPageCreate) in the corresponding ContextProvider class? And how can I pass on the labels in the .soy template? Thank you in advance! smile

Robert Reiner _smartics_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 29, 2015

I have written a Listener, but I assume the ContextProvider would work, too. You may add additional input fields to your soy: ... <form> ... <input type="hidden" name="mykey" value="mayvalue" /> ... These should appear in the context (event or context provider): context.get("mykey").

Robert Reiner _smartics_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 29, 2015

Just in case: Listener @EventListener public void onXyzEvent(final XyzEvent event) { ... }

PJ September 30, 2015

Thanks a lot! I'll implement it and let you know. :)

0 votes
Robert Reiner _smartics_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 29, 2015

I could not manage this with configuration. So I added a listener to listen for events.

Here is some pseudocode (for a space label, but for pages this would be similar):

protected void onPageCreate(final ...Event event) {
    final SpaceBlueprint spaceBlueprint = event.getSpaceBlueprint();
    final String moduleKey = spaceBlueprint.getModuleCompleteKey();
    if (getModuleKey().equals(moduleKey)) { // determine if applicable
      final Space space = event.getSpace();
      final String label = getLabel(); // determine Label to set
      if (!hasLabel(space, label)) {
        labelManager.addLabel(space, label);
      }
    }
  }

Register listener with the atlassian-plugin.xml:

&lt;listener
    key="PageLabelListener"
    class="com.myorg.PageLabelListener" /&gt;
0 votes
PJ September 29, 2015

no one?!

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events