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.
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.
public abstract class ContentReportDataProvider<T> extends Record {
public abstract T run();
}
-
Returns the result of the generated report
Usage Example
public class DataSupplierDataProvider extends ContentReportDataProvider<DataTable> {
@Required
private DataSupplier dataSupplier;
@Override
public DataTable run() {
if (dataSupplier != null) {
return dataSupplier.get();
}
return new DataTable();
}
}
-
Using the
dataSupplier
field, the#run
method is able to return the properDataTable
output type
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.
public abstract class ReportStorage extends Record {
public abstract String createAccessLink(String presentationName);
}
Usage Example
In this implementation of ReportStorage
, the report data is stored within a StorageItem
public class StorageItemReportStorage extends ReportStorage {
private StorageItem storageItem;
public StorageItem getStorageItem() {
return storageItem;
}
public void setStorageItem(StorageItem storageItem) {
this.storageItem = storageItem;
}
public String createAccessLink(String presentationName) {
return BUTTON.with("Download " + presentationName).toString()
+ INPUT.typeHidden().name("storageItemReportStorageId").value(getId().toString()).toString();
}
}
-
This storage data can be accessed through the button's hidden input value
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
).
public abstract class ReportPresentation<D, S extends ReportStorage> {
public abstract S generate(D data);
public abstract String getDisplayName();
}
-
Generates the storage object from the data
-
Returns the display name of the presentation
Usage Example
The following implementation generates the report presentation in CSV format:
class CsvPresentation extends ReportPresentation<DataTable, StorageItemReportStorage> {
@Override
public String getDisplayName() {
return "CSV";
}
@Override
public StorageItemReportStorage generate(DataTable data) {
StorageItem storageItem = StorageItem.Static.create();
storageItem.setContentType("text/csv");
storageItem.setPath(new RandomUuidStorageItemPathGenerator()
.createPath("report.csv"));
/* 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... */
StorageItemReportStorage storageItemReportStorage = new StorageItemReportStorage();
storageItemReportStorage.setStorageItem(storageItem);
return storageItemReportStorage;
}
}