How to automatically create child pages when a new project is created?

I have been trying to write some java code which will listen for when a page is created and automatically generate a set of child pages.

I believe I need some data from the event which I have, but I also need to have a pagemanager and a labelManager.

I'm not sure where to get the data from to construct these two, any help would be much appreicated.

Snippet of the code so far:

@EventListener
public void onBlueprintCreateEvent(BlueprintPageCreateEvent event)
{

 PageManager pageManager;
 LabelManager labelManager;

System.out.println("made it here ...................................");
ModuleCompleteKey moduleCompleteKey = event.getBlueprintKey();

if (!MY_BLUEPRINT_KEY.equals(moduleCompleteKey)){
System.out.println("my_blueprint_key= " + MY_BLUEPRINT_KEY + "moduleCompleteKey= " + moduleCompleteKey.toString());
return;
}

Page topPage = event.getPage();
Space ourSpace = topPage.getSpace();
Map<String,Object> blueprintContext = event.getContext();


System.out.println("2ND PRINT ...................................");
if(topPage == null)
{
System.out.println("topPage EQUALS NULL");
}
if(ourSpace == null)
{
System.out.println("OURSPACE EQUALS NULL");
}

Page subPage = null;
subPage = new Page();


if(pageManager == null)
{
System.out.println("pageManager EQUALS NULL..................................");
}

subPage.setTitle("title");
subPage.setSpace(ourSpace);
subPage.setParentPage(topPage);
subPage.setBodyAsString("NewPage");
subPage.setPosition(0);
//pageManager.saveContentEntity(subPage, null);
//labelManager.addLabel((Labelable) subPage, new Label("NewPage"));


System.out.print("Done....................................................");
}

 

1 answer

Hi Cliff,

 

I think you will need to inject PageManager and LabelManager by using Spring constructor injection or setter injection.

 

private PageManager pageManager;

 

//constructor 

public ClassName(PageManager pageManager) {

    this.pageManager = pageManager;

}

 

Hi Christo,

The problem was @component import needed to be included in the constructor, ill post a snippet below for peoples future reference:

@Scanned
public class MyPageCreatorModule extends AbstractBlueprintContextProvider {

public PageManager pageManager;


public MyPageCreatorModule(@ComponentImport PageManager pageManager) {
this.pageManager = pageManager;
}

 

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

2,694 views 26 10
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you