It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How can I create a page from a blueprint in Java?

This question is in reference to Atlassian Developer Documentation: Custom actions with the Blueprint API

The link above tells us to use com.atlassian.confluence.plugins.createcontent.actions.BlueprintContentGenerator#generateBlueprintPageObject() to create a page from a blueprint. Here's my assumption:

CreateBlueprintPageRequest request = new CreateBlueprintPageRequest(space, "title", null, parentPage, context, templateRef, user, contentBlueprint);
Page instance = blueprintGenerator.generateBlueprintPageObject(request);

All parameters are self-explanatory, except:

  • :cross: templateRef is a ContentTemplateRef, and I can't find any public, non-deprecated method to find it?
  • :cross: ContentBlueprint comes from an "impl" package (com.atlassian.confluence.plugins.createcontent.impl), which is not public, and I can't find a public method to generate it.

Has anyone succeeded to generate a blueprint from Java?

 

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted

ContentBlueprintManager was able to provide it. So here's the code:

 

private Page createPage(Space space, String title, ConfluenceUser user) {
    // Find the blueprint
    ContentBlueprint contentBlueprint = contentBlueprintManager.getPluginBackedContentBlueprint(new ModuleCompleteKey("com.playsql.requirementyogi", "bp-6"), space.getKey());
    if (contentBlueprint == null) {
        throw new RuntimeException("(Your message)");
    }
    ContentTemplateRef templateRef = null;
    for (ContentTemplateRef ref : contentBlueprint.getContentTemplateRefs()) {
        if (equal(ref.getModuleCompleteKey(), "com.playsql.requirementyogi:dictionary-template")) {
            templateRef = ref;
            break;
        }
    }
    if (templateRef == null) {
        throw new RuntimeException("(Your message)");
    }
    
    // Create the instance
    Page parentPage = null;
    Map<String, Object> context = Maps.newHashMap();
    CreateBlueprintPageRequest request = new CreateBlueprintPageRequest(
        space, title,
        null, parentPage,
        context,
        templateRef, user, contentBlueprint);
    Page page = blueprintGenerator.generateBlueprintPageObject(request);
    pageManager.saveContentEntity(page, DefaultSaveContext.DEFAULT);
    return page;
}
TAGS
Community showcase
Posted in Europe

Lakshmi Remani, Krisztian Kovacs; Adaptavist: Video and Slides online

Thanks to Lakshmi for her remarkable debut performance as a community presenter and for Krisztian for giving us the deep dive into Adaptavist's pioneering migration of a large-scale enterprise to the...

48 views 0 0
View post

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you