Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This sample explains how to create a Custom Report for Services in WSO2 Governance Registry in few easy steps. We will be reusing the code of the Handler Sample in this example. This sample requires Apache Maven. See Installing Apache Maven for Governance Registry on Windows or Installing Apache Maven for Governance Registry on Linux.

Alternatives

This sample includes two different alternatives that would in return produce two different types of reports:

...

Info
titleNote

The command mvn clean install will trigger an Apache Maven Build in your command line. This requires you having installed Apache Maven. See Installing Apache Maven for Governance Registry on Windows or Installing Apache Maven for Governance Registry on Linux.

A successful run of Apache Maven will generate a report similar to the following:

...

6. Start the WSO2 Governance Registry. See Starting Governance Registry Management Console on Windows or Starting Governance Registry Management Console on Linux.

7. Navigate to the Resource Browser of Governance Registry and add a new resource as text content with the following parameters:

...

Code Block
languagehtml/xml
<?xml version="1.0" encoding="UTF-8"?>
<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.

Image RemovedImage Added

Read more on Text Content Creation.

Info
titleNote

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.

...

Click the "Add" button to finish adding the report.

Image RemovedImage Added

See the section on Reports to learn how to add reports and manage existing reports.

9. Add a few Services to Governance Registry. Read more on Managing Services.

10. Go to the Manage Reports screen, and select "Generate" to open the Generate Report Screen.

Image RemovedImage Added

11. Finally, click on the "Generate" button to generate the report.

Image RemovedImage Added

You should now find a PDF file named "Service Report.pdf" getting downloaded.

...

Info
titleNote

Report Generator classes can optionally accept attributes. To define attributes, you need to include a method that starts with set along with the @Property annotation. Set mandatory = true to indicate that this is a mandatory attribute. The Load Attributes button can be used to load these attributes.

Image RemovedImage Added

In step 7 of the example above, use the following template:

Code Block
languagehtml/xml
<?xml version="1.0" encoding="UTF-8"?>
<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-Service Comparison" 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="name1" class="java.lang.String"/>
        <field name="name2" class="java.lang.String"/>
        <field name="attr_name" class="java.lang.String"/>
        <field name="attr_value1" class="java.lang.String"/>
        <field name="attr_value2" 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-Service Comparison]]></text>
			</staticText>
		</band>
	</title>
	<pageHeader>
		<band splitType="Stretch"/>
	</pageHeader>
	<columnHeader>
		<band height="29" splitType="Stretch">
			<textField>
				<reportElement x="155" y="0" width="200" height="21"/>
				<textElement textAlignment="Left" verticalAlignment="Middle">
					<font fontName="SansSerif" size="12" isBold="true"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{name1}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement x="355" y="0" width="200" height="21"/>
				<textElement textAlignment="Left" verticalAlignment="Middle">
					<font fontName="SansSerif" size="12" isBold="true"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{name2}]]></textFieldExpression>
			</textField>
		</band>
	</columnHeader>
	<detail>
		<band height="30" splitType="Stretch">
			<textField>
				<reportElement x="0" y="4" width="155" height="20"/>
				<textElement textAlignment="Left" verticalAlignment="Middle"/>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{attr_name}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement x="155" y="4" width="200" height="20"/>
				<textElement textAlignment="Left" verticalAlignment="Middle"/>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{attr_value1}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement x="355" y="4" width="200" height="20"/>
				<textElement textAlignment="Left" verticalAlignment="Middle"/>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{attr_value2}]]></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>

...