Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

Adrien Ragot 2
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 21, 2016

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
Adrien Ragot 2
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 22, 2016

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
AUG Leaders

Atlassian Community Events