The reporting features in JRules Rule Studio build upon the services provided by the Eclipse Business Intelligence and Reporting Tools (BIRT) project. Out of the box we provide BIRT Data Sources to allow you to create customized reports using the BIRT WYSIWYG report designer. This is a good solution for the use cases where you need to make relatively straight-forward customizations to the JRules report templates.
Defining a BIRT Scripted Data Source
The first thing to do is to create your Data Source and assign it the type "Scripted Data Source". You can then create a BIRT Data Set for the Data Source and define the output columns you require.
For my example I defined a generic set of columns that are applicable for most rule artifacts.
Scripting the Data Set
In my example the "open" function was very simple; it simply uses the Rule Studio API to return an iterator over all the Rule Artifacts within a Rule Project. The iterator is then accessed within the "fetch" function.
The "fetch" function is more interesting as it basically implements the Object-to-Column mapping from the Rule Studio POJO model to the columns defined in your Data Set. Note that you can access any variables defined in the "open" function within the "fetch" function! You return "false" from the "fetch" function to indicate that there are no more data rows to process.
The "fetch" method is straightforward, except for the population of the ruleDefinition Data Set column.
row["ruleDefinition"] = renderDefinitionAsHtml( brlRule );
Defining your Report
Defining your report is satisfyingly easy once you find your way around the BIRT user interface. You drag-and-drop report elements onto the report canvas using the Layout view. You can use Header/Footer and Grid elements to iterate on the elements of your Data Set.
Running your Report
You can also define a BIRT Library that defines the Scripted Data Source and the Data Set. This makes it easy to create multiple reports that use your Data Source.
If you take a look at utils.js you will see rather ugly code like this:
if( isBrlRule( ruleArtifact ) )
debug( "BRL Rule: " + ruleArtifact );
brlBundle = Packages.org.eclipse.core.runtime.Platform.getBundle( "ilog.rules.studio.model.brl" );
debug( "brlBundle: " + brlBundle );
brlServiceClass = brlBundle.loadClass( "ilog.rules.studio.model.brl.IlrBRLService" );
debug( "brlServiceClass: " + brlServiceClass );
signature = java.lang.reflect.Array.newInstance( java.lang.Class, 1 );
signature = brlBundle.loadClass( "ilog.rules.studio.model.brl.IlrBRLRule" );
debug( "signature: " + signature );
method = brlServiceClass.getMethod( "getHTMLDefinition", signature );
debug( "method: " + method );
args = java.lang.reflect.Array.newInstance( java.lang.Object, 1 );
args = ruleArtifact;
return method.invoke( null, args );
I found the following references useful while working on the example code. Many thanks to the respective authors for sharing their know-how!