Configuring the JSReport integration
There are two alternatives for configuring the JSReport integration within Brightspot, providing flexibility to accommodate various project requirements.
- Out-of-the-Box Configuration—This approach simplifies the initial configuration process and leverages environment variables to seamlessly provide essential details for the JSReport integration. The required configuration parameters include the JSReport server's URL, username, password, and optional timeout configurations. This straightforward method ensures a quick and efficient setup for users seeking a hassle-free configuration experience
- Custom Configuration API—Recognizing the diverse needs of projects, Brightspot provides an API that allows users to implement bespoke ways of supplying JSReport configuration details. This empowers developers to choose the most suitable configuration approach that best fits the project's unique needs.
Out-of-the-Box Configuration
For the out-of-the-box configuration, the following environment variables need to be supplied:
Key | Type | Description |
brightspot/jsreport/default | java.lang.String | Name of the default configuration to use. Swap in this value for {configName} for the other keys. |
brightspot/jsreport/config/{configName}/class | java.lang.String | Java class name of the JsReportServiceProvider to use. For this out-of-the-box solution the value should be com.psddev.jsreport.DefaultJsReportServiceProvider . |
brightspot/jsreport/config/{configName}/endpoint | java.lang.String | URL used to connect to the JSReport server. |
brightspot/jsreport/config/{configName}/username | java.lang.String | Username used to authenticate with JSReport. |
brightspot/jsreport/config/{configName}/password | java.lang.String | Password used to authenticate with JSReport. |
brightspot/jsreport/config/{configName}/callTimeout | java.lang.String | API Call Timeout in seconds. |
brightspot/jsreport/config/{configName}/connectTimeout | java.lang.String | API Connect Timeout in seconds. |
brightspot/jsreport/config/{configName}/writeTimeout | java.lang.String | API Write Timeout in seconds. |
brightspot/jsreport/config/{configName}/readTimeout | java.lang.String | API Read Timeout in seconds. |
For additional details on environment settings, see Configuring Dari.
Custom Configuration API
To implement the Custom Configuration API for JSReport integration in Brightspot, you extend the provided JsReportServiceProvider
abstract class. This class allows you to define your own method of supplying a JSReport configuration, offering flexibility to adapt to project-specific needs. Below is an example of implementing a JsReportServiceProvider
in which the configuration comes from fields in Brightspot's Sites & Settings admin area.
import com.psddev.cms.db.ToolUi;
import com.psddev.cms.tool.CmsTool;
import com.psddev.dari.db.Modification;
import com.psddev.dari.db.Recordable;
@Recordable.FieldInternalNamePrefix("jsreport.")
public class JsReportGlobalSettings extends Modification<CmsTool> {
private static final String TAB = "Integrations";
private static final String CLUSTER = "JS Report";
@ToolUi.Tab(TAB)
@ToolUi.Cluster(CLUSTER)
private String endpoint;
@ToolUi.Tab(TAB)
@ToolUi.Cluster(CLUSTER)
private String username;
@ToolUi.Tab(TAB)
@ToolUi.Cluster(CLUSTER)
@ToolUi.Secret
private String password;
public String getEndpoint() {
return endpoint;
}
public void setEndpoint(String endpoint) {
this.endpoint = endpoint;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
import java.time.Duration;
import com.psddev.cms.tool.CmsTool;
import com.psddev.dari.db.Singleton;
import com.psddev.jsreport.JsReportServiceProvider;
import net.jsreport.java.service.JsReportService;
import net.jsreport.java.service.JsReportServiceImpl;
import net.jsreport.java.service.ServiceTimeout;
public class JsReportGlobalSettingsServiceProvider extends JsReportServiceProvider {
@Override
public JsReportService getJsReportService() {
JsReportGlobalSettings settings = Singleton.getInstance(CmsTool.class).as(JsReportGlobalSettings.class);
if (settings != null && settings.getEndpoint() != null && settings.getUsername() != null && settings.getPassword() != null) {
ServiceTimeout serviceTimeout = new ServiceTimeout();
serviceTimeout.setCallTimeout(Duration.ofMinutes(1));
serviceTimeout.setConnectTimeout(Duration.ofMinutes(1));
serviceTimeout.setWriteTimeout(Duration.ofMinutes(1));
serviceTimeout.setReadTimeout(Duration.ofMinutes(1));
return new JsReportServiceImpl(
settings.getEndpoint(),
settings.getUsername(),
settings.getPassword(),
serviceTimeout);
}
return null;
}
}
-
A Modification on CMSTool allows us to add new fields to the Sites & Settings admin area. The class contains fields for configuring:
- Endpoint URL
- Username
- Password
-
An extension of JsReportServiceProvider allows us to create custom solution for providing configuration for JsReport.
-
The JsReportGlobalSettings object is retrieved using the BSP Singleton API.
-
A JsReportServiceImpl object is created with the configuration from the JsReportGlobalSettings object.
This custom configuration supplier can then be enabled via the following environment variables:
Key | Type | Description |
brightspot/jsreport/default | java.lang.String | Name of the default configuration to use. Swap in this value for {configName} for the other keys. |
brightspot/jsreport/config/{configName}/class | java.lang.String | Java class name of the JsReportServiceProvider to use. For this out-of-the-box solution the value should be com.yourcompany.JsReportGlobalSettingsServiceProvider . |