Setting a new confluence space homepage using Java API

Hi everyone,

I’m trying to create a new confluence space and copy all the pages to it from another space.
I’ve managed to perform the copying using the deepCopyPage function of the PageManager class.
Here is the code I used for it:

PageCopyOptions pageCopyOptions = PageCopyOptions.builder()
        .withCopyAttachment(true)
        .withCopyLabel(true)
        .withContentProperty(true)
        .withCopyPermission(true)
        .withUser(userUtil.getCurrentUser())
        .withProgressMeter(new ProgressMeter())
        .build();
pageManager.deepCopyPage(pageCopyOptions, templateHomePage, homePage);

templateHomePage is the page of a space I want to copy from
homePage is the home page of the newly created space I want to copy to

Method worked fine besides the issue that now I have the structure of pages in a new space:

  • homePage (current home page)
    • templateHomePage
      • page1
      • page2
      • page3

I am trying to achieve that:

  • templateHomePage (becomes a home page)
    • page1
    • page2
    • page3

That is I want to delete the default homePage of a newly created space and set a templateHomePage as a new homepage.
I tried to use space.setHomePage and then spaceManager.save(space) function but it does nothing, the old homePage is still there.

Has anyone worked with Java API for PageManager and SpaceManager. What is the correct way to achieve what I described above?

Hello @Stas,

your problem is exactly what i was looking for.
Is it possible to post the complete .class to look how it should work? I can’t figure out how it works.

Regards,
Tim

try this:

def spaceManager = ComponentLocator.getComponent(SpaceManager)
def myHomePage = pageManager.getPage(spaceKey, mainPage)
def spaceUpdated = spaceManager.getSpace(spaceKey)

// set a home page and save!
spaceUpdated.setHomePage(myHomePage)
spaceManager.saveSpace(spaceUpdated)

it´s worked for me

Can we exclude the children to coy from orginalPage to destination Page