Brightspot Integrations Guide

JSReport document generation API


The JsReportDocumentGenerator utility class in Brightspot simplifies the process of generating documents using JSReport. This utility class provides two distinct methods, catering to different use cases, allowing developers to seamlessly integrate JSReport document generation within their Brightspot projects. This topic describes each method and its use cases.


createDocument(String template, Object data)

Creates a Document for the specified JSReport template and input data.

  • Parameters:
    • template: The JSReport template to use, specified by either the template name or short ID.
    • data: The data used to render the JSReport template, typically represented as a java.util.Map to convey JSON data.
  • Return:
    • A Document object containing the document produced by JSReport, including the document's content and content type.

Usage example

String templateName = "myTemplate";
Map<String, Object> jsonData = // ... prepare JSON data
Document generatedDocument = JsReportDocumentGenerator.createDocument(templateName, jsonData);


createDocument(String template, Class dateEntryView, Object content)

Creates a Document using the specified template, dateEntryView, and content, leveraging the Brightspot view system.

  • Parameters:
    • template: The entry view used to find an appropriate view model. If null, the DefaultJsReportTemplate annotation will be checked for a default template.
    • dateEntryView: The entry view used to find an appropriate view model.
    • content: The content providing data for document generation.
  • Return:
    • A Document object containing the document produced by JSReport, including the document's content and content type.

Usage example

Object content = Query.from(MyRecord.class).first(); // contrived example for getting cotent from BSP DB
Document generatedDocument = JsReportDocumentGenerator.createDocument(null, JsReportViewModel.class, content);

@JsonView
@ViewInterface
@DefaultJsReportTemplate("myPdf")
public class JsReportViewModel extends ViewModel<MyRecord> {
    
    public String getTitle() {
        return model.getHeadline();
    }

    public String getCompany() {
        return model.getCompany();
    }
}
  • Specifies that the ViewModel can be converted to JSON, which is the primary format JSReport accepts.
  • Specifies that the ViewModel is a ViewInterface, meaning any public getter methods are included in data.
  • Specifies that the default JSReport template to use for this viewmodel has the name "myPdf". This will be used in the API call from line #2 since a null value was passed for the template parameter.
  • Marks this class as a ViewModel for the "MyRecord" class.
  • This will result in a "title" key in the resulting JSON passed to JSReport.
  • This will result in a "company" key in the resulting JSON passed to JSReport.

Previous Topic
Configuring the JSReport integration
Next Topic
Enabling JSReport preview
Was this topic helpful?
Thanks for your feedback.
Our robust, flexible Design System provides hundreds of pre-built components you can use to build the presentation layer of your dreams.

Asset types
Module types
Page types
Brightspot is packaged with content types that get you up and running in a matter of days, including assets, modules and landing pages.

Content types
Modules
Landing pages
Everything you need to know when creating, managing, and administering content within Brightspot CMS.

Dashboards
Publishing
Workflows
Admin configurations
A guide for installing, supporting, extending, modifying and administering code on the Brightspot platform.

Field types
Content modeling
Rich-text elements
Images
A guide to configuring Brightspot's library of integrations, including pre-built options and developer-configured extensions.

Google Analytics
Shopify
Apple News