The reporting-environment came to life as a simple way to inject runtime information from the platform into a report. Ideally, a report should not know about details from the server it runs on. Certain parts of the server’s configuration, like the server’s base-url, easily change when the report travels from development to the test and then to the production environment.
Earlier versions relied on magical string replacements during the parse process to inject that kind of information. Parse-time modifications are generally a bad thing. They are insecure,
as every String manipulation of XML files is. If you manage to get a valid XML-Fragment into your replacement string, you can do everything. There is no way a GUI tool could be written for it. The injection magically happens everywhere without giving the user a say on that matter. At design time, or outside of the legacy code of the Pentaho Platform’s JFreeReportComponent, this replacement does not happen. I don’t want to explain that mad system to anyone, and surely neither do you!
And finally: It really makes it hard to do caching inside the reporting engine. For the reporting engine, these replaced strings look exactly like static strings and all of the sudden the cache is poisoned with a invalid copy.
Moving that information from parse-time to runtime solves that problem for me.
The report-environment is a special interface that allows third party systems like the Pentaho BI-Server to inject configuration settings in a safe and pre-defined way. That configuration information is then available to all expressions and functions. It completely eliminates all magic from the report processing.
A report-environment entry is not a parameter. A parameter is a external value that has been provided by the user or that has been calculated from end-user or report-designer input. A
report-environment property comes solely from the local runtime environment.
Inside the reporting engine, a report-environment setting is a single string. The setting is either one of the well-known environment-keys provided by the runtime implementation, a session-entry or a user-defined environment setting.
The server’s base URL without any servlet context. Use this one to link to other resources on the same server.
The server’s base url including the local web-application context. Use this one to link to other Pentaho Services.
The solution-repository root directory.
The host name and port, without the protocol prefix or any path information.
The context path of the web-application
The username of the currently logged in user.
The set of roles the user is assigned to.
A environment setting starting with the prefix “
session:” will be treated as a local session lookup. A session lookup will only work inside the Pentaho BI-Server. The BI-Server will compute the session attribute name by removing the “
session:” prefix and will lookup the value in the users HTTP-Session instance.
If the value found there is a string it will be returned as valid entry. If the value is a string array, it will be converted into a CSV text using the excel quoting syntax (double-quote-character
are quote characters, and text containing either the comma, a quote character or a line-break will be quoted.
Joe, the horse, says "Ho" will become
"Joe, the horse, says ""Ho""".
You can use the
CSVARRAY formula function to parse that text back into a String-array inside the reporting engine.
User-Defined Environment setting
If a key does not match either one of the well-known keys or if the engine cannot identify it as a session-entry, it will be treated as user-defined setting. The reporting engine will consult the global configuration and will try to find the value by appending the environment key to the configuration prefix “
Therefore a environment lookup for the key “
Foo” will query the global configuration for a configuration entry called “
How to use them
The report-environment can be accessed via the OpenFormula function
The result of the lookup can be used in the same formula:
=ENV("pentahoBaseURL") & "/content/reporting/report.html?solution=steel-wheels&path=reports&name=BuyerReport.prpt"
You can also make the value accessible as a separate field. Place the ENV lookup into the post-processing formula of a hidden parameter or into the “formula” property of a OpenFormula-Expression and the value appears as field.
But there is a easier way to convert your environment lookups into fields!
The auto-mapping definitions allow the Pentaho Reporting Engine to automatically lookup a set of report-environment keys and to publish those values as “
env::” fields. Which fields are auto-mapped is controlled by a set of configuration entries in the reporting engine’s global configuration.
A mapping rule follows the following syntax:
If the environment string is a CSV string, you can tell the reporting engine about it and it will produce a field that contains a String-array.
It is generally a good idea to keep your environment fields in a separate namespace by using the “env::” prefix for your fields. This way you will not run into conflicts with fields from your database or expressions later on. I also heavily recommend to try to keep the reference to the environment key in the name, this provides a sensible self-documenting entry.
Where to use Report-Environment fields
The second group ,”username” and “roles” is used to enforce security rules in datasources or on calculations.
The third use-case would be to provide system dependent parametrization, like printing static text. It is a easy way to include the department name or the name of the staging system (test, dev, production) in every report.
And last but not least: The environment is accessible to scripts and formulas, so it can be used as a system wide parametrization avenue.
Setting up session values
Setting up global user-defined report-environment values
The global user-defined report-environment values are defined in the reporting engine’s global “classic-engine.properties” file. You will find that file in the Pentaho-Report-Designer’s “
resources” directory. The BI-Server’s global reporting configuration file can be found in the
The report-environment is a simple and easy to setup way to make your reports more reusable. Whenever you find yourself changing reports manually while transitioning them from development to testing or production, you now have the tools at hand to elimenate these manual steps.