Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Confluence Space Blueprint and SpaceCreateEvent EventListener

Simon Neuville
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 7, 2020

Hello Atlassian Community!

 

I'm in the process of creating a Confluence Space Blueprint, which needs to work in harmony with an EventListener I implemented. As far as I understand, the order in which events happen and the blueprint is applied is the root cause.

 

Requirement

The following are a few requirements I set for my solution, which should (hopefully) give you a pretty good idea what I want to achieve.

  1. When the user creates a new space of the type "myCustomSpace", he should be presented with a custom creation wizard. This wizard should allow him to specify what kind of project category he'd like to create.
  2. When the Space is created, a page tree from a different Space should be copied. The top-level page  of that page tree has to be the home page of my newly created project.

Context

The solution I came up for each point, respectively is:

  1. Implement my own Confluence Space Blueprint. Although rudimentary, the creation wizard has the fields I need. The values of those fields are written to the homepage. In a later step it would be really preferable if I could specify the label/category of the space through these fields. However, that is not the problem described in this post.
  2. Using the ScriptRunner Plugin, I created an eventlistener that listens to the SpaceCreateEvent. When this event is caught, the page tree from a hard coded space is copied over using the CopyPageTree built-in script.

On their own, these solutions seem to work fine.

 

Problem

When I combine these two solutions and attempt to create a project, there are (unexpectedly) two top-level pages: the homepage created by the Space Blueprint, and the top-level page of the copied pagetree.

The expected behaviour is to have one top-level page (homepage), with the copied pagetree as a child. If I create a different kind of project (i.e. do not use the Space Blueprint), this works as expected.

 

The root cause of this problem (after some debugging) seems to be the order in which events occur. More specifically, this is what seems to happen:

  1. User clicks "Create" through the Space Blueprint custom creation wizard
  2. Space is created with a standard homepage (not the homepage that I defined in the Blueprint)
  3. SpaceCreateEvent is dispatched
  4. The eventlistener is triggerred. The page tree is copied. At this point, the page structure is as-desired.
  5. Confluence Space Blueprint still needs to apply my custom content: the homepage. To do so, it deleted the current homepage and created one. By doing so, it causes its only child-page (top-level page of the copied pagetee) to become an orphan and be promoted to a top-level page in this space.

This leaves the structure in an undesired state.

 

I have thought of the following solutions, but lack the knowledge/documentation to implement any of those:

  • Start a new thread for the eventlistener and let that thread sleep, so the copy of the pagetree would be executed later. Tried this without success (code inside Thread.start({}) was not executed.
  • Finding another event to have the listener trigger on... which one and what additional validations there would have to be is unclear to me still.

 

 

Any thoughts, ideas or help would be greatly appreciated.

 

Kind regards,

Simon

 

 

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events