Editorial content report APIs
While the editorial content reports feature can be utilized without any additional development, the following APIs can be leveraged in order to further customize how reports are generated, stored, and/or presented.
Content Report Data Provider
The ContentReportDataProvider class is used for generating the output of a report. This class is customizable, allowing users to define the expected output (T) of the report. The return type is open-ended, allowing reports to be grouped as any type of output.
1public abstract class ContentReportDataProvider<T> extends Record {23public abstract T run();4}
- 3. Returns the result of the generated report
Usage Example
1public class DataSupplierDataProvider extends ContentReportDataProvider<DataTable> {23@Required4private DataSupplier dataSupplier;56@Override7public DataTable run() {8if (dataSupplier != null) {9return dataSupplier.get();10}11return new DataTable();12}1314}
- 11. Using the
dataSupplierfield, the#runmethod is able to return the properDataTableoutput type
Report Storage
The ReportStorage class represents how the output of the report is stored. It provides a method to create an HTML access link for users to access the report from the CMS however they prefer.
1public abstract class ReportStorage extends Record {23public abstract String createAccessLink(String presentationName);45}
Usage Example
In this implementation of ReportStorage, the report data is stored within a StorageItem
1public class StorageItemReportStorage extends ReportStorage {23private StorageItem storageItem;45public StorageItem getStorageItem() {6return storageItem;7}89public void setStorageItem(StorageItem storageItem) {10this.storageItem = storageItem;11}1213public String createAccessLink(String presentationName) {14return BUTTON.with("Download " + presentationName).toString()15+ INPUT.typeHidden().name("storageItemReportStorageId").value(getId().toString()).toString();16}17}
- 14. This storage data can be accessed through the button's hidden input value
Report Presentation
The ReportPresentation class represents different formats in which data can be presented. Sub-classes must specify the input type (D) and the storage type (S).
1public abstract class ReportPresentation<D, S extends ReportStorage> {23public abstract S generate(D data);45public abstract String getDisplayName();67}
- 3. Generates the storage object from the data
- 5. Returns the display name of the presentation
Usage Example
The following implementation generates the report presentation in CSV format:
1class CsvPresentation extends ReportPresentation<DataTable, StorageItemReportStorage> {23@Override4public String getDisplayName() {5return "CSV";6}78@Override9public StorageItemReportStorage generate(DataTable data) {10StorageItem storageItem = StorageItem.Static.create();11storageItem.setContentType("text/csv");12storageItem.setPath(new RandomUuidStorageItemPathGenerator()13.createPath("report.csv"));14/* Handle construction of the report text in CSV format using the DataTable data value, and then set the CSV file contents to the storageItem field here... */15StorageItemReportStorage storageItemReportStorage = new StorageItemReportStorage();16storageItemReportStorage.setStorageItem(storageItem);17return storageItemReportStorage;18}19}