Hello, I am new at Confluence plugin development and I have faced with a problem.
I have generated a couple of pages with Confluence Java API. I can see all generated pages on the "Recently Updated". Instead of that, pages are not appearing on the tree browser. I have tried to create a page manually just after the all pages are generated and then all pages including the pages which did not appear in the tree browser, appeared. Is there any way to handle this problem. Thanks.
Hi Orkun,
You can try create a page with the correct state, and then index the page.
Something similar to this:
private void createPage(String title, String space) {
Page parentPage;
Page newPage = new Page();
newPage.setSpace(spaceManager.getSpace(space));
newPage.setTitle(title);
newPage.setCreationDate(new Date());
newPage.setCreator(AuthenticatedUserThreadLocal.get());
newPage.setVersion(1);
parentPage = pageManager.getPage(space, parentPageTitleHere);
setParentPage(newPage, parentPage);
pageManager.saveContentEntity(newPage, new DefaultSaveContext(false, false, false));
parentPage.addChild(pageManager.getPage(space, title));
confluenceIndexer.reIndex(newPage);
}
private void setParentPage(Page newPage, Page parent) {
List<Page> ancestors = new ArrayList<>();
ancestors.add(parent);
newPage.setAncestors(ancestors);
newPage.setParentPage(parent);
}
Note that it is not good enough to just set the parent of the newly created page. You must also on the parent page set the new page as a child.
Let me know if this helps, and if it answers your question then please mark it as answered.
Thanks a lot Christo for your answer. The problem that I could not handle is using
confluenceIndexer.reIndex(newPage);
Could you please give me a hint about usage of ConfluenceIndexer?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sure, you will have to inject the ConfluenceIndexer via constructor or setter injection.
In my example I have done it via setter injection because it was used in an action which does not work with constructor injection.
Something like:
private ConfluenceIndexer confluenceIndexer;
public void setConfluenceIndexer(ConfluenceIndexer confluenceIndexer) {
this.confluenceIndexer = confluenceIndexer;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you miss the line:
parentPage.addChild(pageManager.getPage(space, title));
... then the page gets created inside of the database but you cannot see it on Confluence.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.