...
- Navigate to
GREG_HOME/
samples/handler/src
to find the source code of the Handler Sample. Add the following dependency to your POM file:. Make sure you update the current version of the registry (e.g. 4.4.3) and carbon governance (e.g. 4.5.1).
Info Project Object Model (POM) is an XML representation of a Maven project held in a file named pom.xml. You should find POM file by the name pom.xml inside
GREG_HOME/
samples/handler/src
.Code Block language html/xml <dependency> <groupId>org.wso2.carbon.carbon<registry</groupId> <artifactId>org.wso2.carbon.registry.reporting</artifactId> <version> {current version of <version>4.2.0<the registry}</version> </dependency> <dependency> <groupId>org.wso2.carbon</groupId> <artifactId>org.wso2.carbon.reporting.api</artifactId> <version>4.2.0</version> </dependency> <dependency> <groupId>org.wso2.carbon</groupId> <artifactId>org.wso2.carbon.reporting.util</artifactId> <version>4.2.0</version> </dependency> <dependency> <groupId>org.wso2.carbon.carbon<governance</groupId> <artifactId>org.wso2.carbon.governance.api</artifactId> <version>{current version of <version>4.2.1<the governance}</version> </dependency>
Add a new Java Class named
ServiceReportGenerator
at named ServiceReportGenerator atGREG_HOME/samples/handler/src/src/main/java/org/wso2/carbon/registry/samples/reporting/ServiceReportGenerator.java
with the following source:Code Block language java package org.wso2.carbon.registry.samples.reporting; import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource; import org.wso2.carbon.governance.api.services.ServiceManager; import org.wso2.carbon.governance.api.services.dataobjects.Service; import org.wso2.carbon.governance.api.util.GovernanceUtils; import org.wso2.carbon.registry.core.Registry; import org.wso2.carbon.registry.core.session.CurrentSession; import org.wso2.carbon.registry.core.utils.RegistryUtils; import org.wso2.carbon.registry.reporting.AbstractReportGenerator; import org.wso2.carbon.reporting.util.JasperPrintProvider; import org.wso2.carbon.reporting.util.ReportParamMap; import org.wso2.carbon.reporting.util.ReportStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.LinkedList; import java.util.List; public class ServiceReportGenerator extends AbstractReportGenerator { public ByteArrayOutputStream execute(String template, String type) throws IOException { try { Registry registry = getRegistry(); // Read Template String templateContent = RegistryUtils.decodeBytes( (byte[]) registry.get(template).getContent()); // Create Report Bean Collection ServiceManager manager = new ServiceManager( GovernanceUtils.getGovernanceUserRegistry(registry, CurrentSession.getUser())); List<ReportBean> beanList = new LinkedList<ReportBean>(); for (Service artifact : manager.getAllServices()) { beanList.add(new ReportBean(artifact.getAttribute("overview_name"), artifact.getAttribute("overview_version"), artifact.getAttribute("overview_description"))); } // Generate Report Stream return new ReportStream().getReportStream(new JasperPrintProvider().createJasperPrint( new JRBeanCollectionDataSource(beanList), templateContent, new ReportParamMap[0]), type); } catch (Exception e) { e.printStackTrace(); } return new ByteArrayOutputStream(0); } public static class ReportBean { private String overview_name; private String overview_version; private String overview_description; public ReportBean(String overview_name, String overview_version, String overview_description) { this.overview_name = overview_name; this.overview_version = overview_version; this.overview_description = overview_description; } public String getOverview_name() { return overview_name; } public String getOverview_version() { return overview_version; } public String getOverview_description() { return overview_description; } } }
Info The WSO2 Governance Registry uses the Jasper Reporting Engine. Learn more on Jasper Reporting APIs to generate more elegant reports.
Compile the source code by running the following command inside
GREG_HOME/
samplessamples/handler/src
:Code Block mvn clean install
Info The command
mvn clean install
will trigger an Apache Maven Build in your command line. This requires you having installed Apache Maven. See Installation Prerequisites for links on how to install it.A successful run of Apache Maven will generate a report similar to the following:
- Copy the
GREG_HOME/
samples/handler/src/target/
org.wso2.carbon.registry.samples.handler-4.5.0.jar
intoGREG_HOME/repository/components/dropins
. - Start the WSO2 Governance Registry. See Running the Product for more information.
- Navigate to the Resource Browser of Governance Registry and add a new resource as text content with the following parameters:
- Name - /_system/governance/repository/components/org.wso2.carbon.governance/templates/service_template.jrxml
- Media Type - application/xml
Content - (Copy the content below)
Code Block language html/xml <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Service List Report" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20"> <property name="ireport.zoom" value="1.3310000000000068"/> <property name="ireport.x" value="0"/> <property name="ireport.y" value="0"/> <field name="overview_name" class="java.lang.String"/> <field name="overview_version" class="java.lang.String"/> <field name="overview_description" class="java.lang.String"/> <background> <band height="802" splitType="Stretch"/> </background> <title> <band height="52" splitType="Stretch"> <staticText> <reportElement x="0" y="9" width="555" height="27"/> <textElement textAlignment="Center" verticalAlignment="Middle"> <font fontName="SansSerif" size="20"/> </textElement> <text><![CDATA[Service List Report]]></text> </staticText> </band> </title> <pageHeader> <band splitType="Stretch"/> </pageHeader> <columnHeader> <band height="29" splitType="Stretch"> <staticText> <reportElement x="0" y="0" width="150" height="21"/> <textElement textAlignment="Left" verticalAlignment="Middle"> <font fontName="SansSerif" size="12" isBold="true"/> </textElement> <text><![CDATA[Name]]></text> </staticText> <staticText> <reportElement x="150" y="0" width="305" height="21"/> <textElement textAlignment="Center" verticalAlignment="Middle"> <font fontName="SansSerif" size="12" isBold="true"/> </textElement> <text><![CDATA[Version]]></text> </staticText> <line> <reportElement x="0" y="21" width="555" height="1"/> </line> <staticText> <reportElement x="455" y="0" width="100" height="21"/> <textElement textAlignment="Center" verticalAlignment="Middle"> <font fontName="SansSerif" size="12" isBold="true"/> </textElement> <text><![CDATA[Description]]></text> </staticText> </band> </columnHeader> <detail> <band height="30" splitType="Stretch"> <textField> <reportElement x="0" y="4" width="305" height="20"/> <textElement textAlignment="Center" verticalAlignment="Middle"/> <textFieldExpression class="java.lang.String"><![CDATA[$F{overview_name}]]></textFieldExpression> </textField> <textField> <reportElement x="305" y="4" width="150" height="20"/> <textElement textAlignment="Left" verticalAlignment="Middle"/> <textFieldExpression class="java.lang.String"><![CDATA[$F{overview_version}]]></textFieldExpression> </textField> <textField> <reportElement x="455" y="4" width="100" height="20"/> <textElement textAlignment="Center" verticalAlignment="Middle"/> <textFieldExpression class="java.lang.String"><![CDATA[$F{overview_description}]]></textFieldExpression> </textField> </band> </detail> <columnFooter> <band splitType="Stretch"/> </columnFooter> <pageFooter> <band height="29" splitType="Stretch"> <staticText> <reportElement x="0" y="3" width="204" height="18"/> <textElement verticalAlignment="Top"> <font size="8"/> </textElement> <text><![CDATA[Created with WSO2 Governanace Registry]]></text> </staticText> <line> <reportElement x="0" y="1" width="555" height="1"/> </line> <textField> <reportElement x="246" y="2" width="80" height="20"/> <textElement textAlignment="Right"> <font size="8"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression> </textField> <textField evaluationTime="Report"> <reportElement x="327" y="2" width="69" height="20"/> <textElement> <font size="8"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression> </textField> <textField pattern="dd/MM/yyyy HH.mm.ss"> <reportElement x="456" y="3" width="99" height="18"/> <textElement textAlignment="Center"> <font size="8"/> </textElement> <textFieldExpression class="java.util.Date"><![CDATA[new java.util.Date()]]></textFieldExpression> </textField> </band> </pageFooter> <summary> <band splitType="Stretch"/> </summary> </jasperReport>
Click the "Add" button to finish adding the text content.
Read more on Text Content Creation.Info The WSO2 Governance Registry uses the Jasper Reporting Engine. The Template File that you created is a Jasper Report Template (.jrxml). Learn more on how to use tools like iReport to generate these template files.
- Now, you need to Add a new Report using the following parameters:
- Report Name - Service Report
- Template - /_system/governance/repository/components/org.wso2.carbon.governance/templates/service_template.jrxml
- Report Type - PDF
- Report Class - org.wso2.carbon.registry.samples.reporting.ServiceReportGenerator
- Click the "Add" button to finish adding the report.
See the section on Reports to learn how to add reports and manage existing reports. - Add a few Services to Governance Registry. Read more on /wiki/spaces/~yohanna@wso2.com/pages/21233672.
- Go to the Manage Reports screen, and select "Generate" to open the Generate Report Screen.
- Finally, click on the "Generate" button to generate the report.
You should now find a PDF file named "Service Report.pdf" getting downloaded.
Instructions 2
Create two new services called "CXFService" and "Axis2service" before generating the report. For information on adding a service, see Managing Services.
In step 3 of the example above, use the following code in ServiceReportGenerator
at GREG_HOME/samples/handler/src/src/main/java/org/wso2/carbon/registry/samples/reporting/ServiceReportGenerator.java
:
...