WSO2 Governance Registry has many features that helps users to store and manage different types of data including Service metadata, WSDLs, Word Documents, PDF Documents, Text Documents and may more. It also has features that help users to navigate and search for any resource that is stored in the Registry/Repository. Apart from the tree view and metadata search of resources, WSO2 Governance Registry has a feature where users can define custom report generation for any types of artifacts.
In this post, I'm focusing on adding a custom report that helps users to generate reports about services and policies that are stored in the Governance Registry.
In this post, I'm going to add a custom report that lists out all the Services and Policies that are stored in the Governance Registry. The report contains the following metadata about Services and Policies.
The generated report is structured in the following manner.
WSO2 Governance Registry uses the JasperReports library for generating reports. A user can define his own Jasper Report template(extension .jrxml) and a java class that injects data into that report and add it to the Governance Registry.
I have created a custom Jasper Report template and a GovernanceReportGenerator class that extends the org.wso2.carbon.registry.reporting.AbstractReportGenerator class to inject data into that reporting template.
The report template is written in a Generic manner so that it will generate different tables for each of the data type. In this sample, I'm only sending data related to Services and Policies. The report template expects data sets which have sub data sets included in them.
We need to do few things in order to add this report generation to WSO2 Governance Registry. If you have not used WSO2 Governance Registry before, download the distribution using this page, unpack the distribution and start the server. More information on how to install and start the server can be found here.
In this post, I'm focusing on adding a custom report that helps users to generate reports about services and policies that are stored in the Governance Registry.
Support for Report Generation
WSO2 Governance Registry has the capability of generating reports for metadata and activity search results. With this feature, a user has the ability to export the search results as a PDF, Excel or HTML report. A sample report that was generated using a metadata search result is given below.
As you can see, this is a basic report that is generated with the search results and there is no easy way of adding more fields and changing the report layout. But the WSO2 Governance Registry has an extension point where you can add your own report template and add your own data set and generate reports using that report template.In this post, I'm going to add a custom report that lists out all the Services and Policies that are stored in the Governance Registry. The report contains the following metadata about Services and Policies.
- Name
- Version
- Description
- Relationships(Dependencies and Associations)
- Lifecycle state
The generated report is structured in the following manner.
Custom Reports
I have created a custom Jasper Report template and a GovernanceReportGenerator class that extends the org.wso2.carbon.registry.reporting.AbstractReportGenerator class to inject data into that reporting template.
Reporting template
The structure of the reporting template is as follows. I have used the iReport Designer to design this reporting template.
The report template is written in a Generic manner so that it will generate different tables for each of the data type. In this sample, I'm only sending data related to Services and Policies. The report template expects data sets which have sub data sets included in them.
GovernanceReportGenerator
The GovernanceReportGenerator class is responsible for fetching the data from the Governance Registry and creating the data collection structure which is expected by the report template. The GovernanceReportGenerator class uses a JRBeanCollectionDataSource as the datasource of the report. The class does two main operations.
- Fetch the pre-defined governance artifacts from Governance Registry. This class fetch data related to Services and Policies using the Governance API of the WSO2 Governance Registry.
- Create the Bean structure for the JRBeanCollectionDataSource. The datasource is structured in the following manner. For all the JRBeanCollectionDataSources We pass a list of corresponding beans.
The full source of GovernanceReportGenerator.java is as follows. All of these classes have been defined as inner classes of GovernanceReportGenerator.java.
GovernanceReportGenerator.java
How to Add The Custom Report
We need to do few things in order to add this report generation to WSO2 Governance Registry. If you have not used WSO2 Governance Registry before, download the distribution using this page, unpack the distribution and start the server. More information on how to install and start the server can be found here.
- First we need to add the compiled .jar file to the server. We can do that from the Extensions menu in the Management Console.
Once the extension is added, you can see it in the list view. - Next we need to add the Report Template to the Registry Server. This can be added as a regular resource. Therefore I have added the governance_template.jrxml to the /_system/governance/customReports/governance_template.jrxml location.
- The report template expects a logo resource. I have added the logo.png to the same location where I have added the Report Template. I have given system/wso2.anonymous.role read permissions for this resource too.
- Then we can add the report to the Registry Server. We can do that from the Management Console of the server. When adding the report, you need to specify the following.
- Report Name - A unique name for the report.
- Template - The resource location of the .jrxml file. In this scenario I have given /_system/governance/customReports/governance_template.jrxml as the report location.
- Report type - I have specified PDF. This can be changed later if required.
- Report class - Need to give the full qualified class name of the class we added in the initial step. For this sample I have given org.wso2.carbon.registry.samples.reporting.GovernanceReportGenerator as the full qualified class name. Once we define the class name we can click on the Load Attributes button. That will load the additional attributes that we have defined in our GovernanceReportGenerator.java.
- Description - The description that needs to be added to the generated report. This is a custom attribute that I have defined in my source. If we leave this as empty, then a default description is added.
- Report Title - The tile of the generated report. This is also a custom attribute and leaving it empty would set a default title.
- Report Logo - The location of the logo that we have added previously. This is also a custom attribute and if left empty, the Report Generator will look for a logo under /_system/governance/repository/images/logo.png location.
- Once the above steps are completed we see the added report in the reports list.
- Now, by clicking on the Generate link, we can create a report of services and policies with above mentioned reporting template. You also have the option of scheduling the report generation.
Complete Source
The complete source of this sample can be found in my Github location using this link. You are welcome to improve this sample.