Drill Down Report: Passing parameters from main report to the drill down report in Jasper Server

Drill Down Report: Passing parameters from main report to the drill down report in Jasper Server

 While we create a report using an Ad-hoc view, there are times when we use Drill down reports in the Dashboard. Drill down report has to have a main report linking to it or a parent report. When the main report generates the result ,upon clicking on the part of the result,the drill down report should take the appropriate parameters to show the actual results.

Following are the steps to follow to ensure the parameters are passed properly from parent report/main report to the drill down report.

The image below is our parent report:blog_1

Now the above report has Year and Group as a filter that has to be passed to the drill down report as a parameter. When clicked on any of the bar from march the month parameter should pass to the drill down report as a month parameter along with the Year and group parameter.

The image shown below is the drilled down report for the month of may,year and group taken from the parent report.

blog_2

To link both the reports, mention the hyperlink of the child report  under properties option, link the parameters.

blog_3

Link the parameters in the hyperlink box with the respective filters/field names as shown below:

http://testjasper/jasperserver-pro/flow.html?_flowId=viewReportFlow&standAlone=true&ParentFolderUri=/Group_Health_Sample/Domain&reportUnit=/Group_Health_Sample/Domain/Participant_Details_Report&Billing_Month_1=$P{Billing Month}&Coverage_Category_1=$P{Coverage Category}&$P{ “Billing_Year_1=”,Billing_Year_1,”&”}$P{ “group_name_1=”,group_name_1,”&”}

By doing this now we have linked the parent report with the drill down report.

 

 

Audit Diagnostic & Monitoring of reports in jasper server pro 6.3

Auditing stores key events that are of interest to system administrators, such as login/logout time, user, report generated, report details, and object sizes. The audited events can be saved and moved to an archive automatically after a specified number of days.

Monitoring is based on audit events and provides a multi-dimensional Domain to create Ad Hoc views. This helps you generate reports that contain key metrics such as which reports use the most resources. This allow you to find places to optimize your data sources and your reports.

Diagnostics provide run-time data that gives the overall health of your server instance. For example, it includes load values such as the number of logged in user, the number of currently running reports, and the number of scheduled reports. The diagnostic data is exposed in a custom data source and can be easily viewed in a report or integrated with industry standard management consoles.

Events Being Audited and Monitored :

http://community.jaspersoft.com/documentation/jasperreports-server-administration-guide/v550/events-being-audited-and-monitored

Configuring Auditing and Monitoring :

http://community.jaspersoft.com/documentation/jasperreports-server-administration-guide/v550/configuring-auditing-and-monitoring

Go to ./WEB-INF/js.config.properties

audit.sizeof.enabled=true
audit.records.enabled=true
feature.audit_monitoring.enabled=true
monitoring.records.enabled=true

Set this property to true to enable the auditing and monitoring subsystem. Given the default value of the other settings, only auditing is turned on when this setting is first set to true.

Using the Audit Data :
JasperReports Server makes the audit data available to administrators through Domains and several prepared views and reports. These are located in the /Public/Audit folder of the repository.

There are two Domains and two sets of reports created for accessing audit data:
•Audit Domain and Audit Reports – Use these to view the current audit data; they run against the active audit database.
•Audit Archive Domain and Archived Audit Reports – Use these to run reports on archived data; they run against the archive database.
The contents of both Domains and reports are identical—they differ only in the database tables that are accessed in each case.
To create an Ad Hoc View based on the audit Domains, select Create > Ad Hoc View, select the Domains tab in the Data Chooser, and expand the folders to select one of the audit Domains.
Audit Reports and Ad Hoc Views :

The following views and reports are provided:
•Audit Report – Generic example of a an audit report showing commonly audited events.
•Performance Crosstab Report – A crosstab that shows average performance of reports that were run.
•Performance Report – Generates a list of reports that were run and sorted by run-time to identify slow reports.
•Repository Resources Report – Shows repository resources and their associated events.
•Resource Execution Report – Generates a list of reports that were run.
•User Activity Report – Generates a list of reports run by a specific user.

http://community.jaspersoft.com/documentation/jasperreports-server-administration-guide/v550/using-audit-data

Using the Monitoring Data :

JasperReports Server makes the monitoring data available to administrators through a Domain and several prepared views and reports. These are located in the /Public/Monitoring folder of the repository.

Monitoring Views and Reports :

The monitoring reports and their views are blank by default, because the audit subsystem that monitoring depends upon is disabled by default and no audit data exists. To view these reports, first enable auditing as described in section Configuring Auditing and Monitoring, then wait for user activity to generate events.
A number of Ad Hoc views based on the monitoring Domain are provided in the Public/Monitoring/Monitoring Reports folder.

The reports are designed to cover common monitoring needs and can be used as-is. When monitoring is enabled and audit events are being recorded, the reports will contain up-to-the-minute records of events on your server. You can run the reports or schedule them as needed.

The Ad Hoc view used to create each report is included as well. You can open these in the Ad Hoc editor to explore the monitoring data in real-time. You can also modify these views in the Ad Hoc Editor to generate new reports to suit your monitoring requirements.

The following views and reports are provided:
•Report Monitoring Resources Report – Gives a list of all reports that were run and shows their average and high-low runtimes.
•Report Monitoring Details Report – A crosstab that shows report runtimes on one axis and many dimensions such as a time hierarchy, user and organization, and event type on the other axis

http://community.jaspersoft.com/documentation/jasperreports-server-administration-guide/v550/using-monitoring-data
Using the Diagnostic Data In Reports :

JasperReports Server makes the diagnostic data available to administrators for internal reports. The following resources are visible to the system admin (superuser by default) in the repository:

•/Public/Diagnostic/Diagnostic Data Source – A custom data source that returns all of the diagnostic fields.
•/Public/Diagnostic/Diagnostic Report – A report that displays nearly every single diagnostic field.
•/Public/Ad Hoc Components/Topics/Diagnostic Topic – A JRXML resource that can be used as a Topic to create an Ad Hoc view using diagnostic fields.

http://community.jaspersoft.com/documentation/jasperreports-server-administration-guide/v550/using-diagnostic-data-reports

Excluding Diagnostic Attributes :

The JasperReports Server diagnostic feature exposes a set of managed beans (MBeans), each with a number of JMX attributes. By default, all attributes of all MBeans are available. If you would like to limit what is exposed, you can exclude any of the attributes or entire beans through the following configuration file:
…/WEB-INF/applicationContext-diagnostic.xml
•To exclude an attribute, locate the MBean where it is defined and uncomment it from the excludedDiagnosticAttributes property. For example, if you want to hide sensitive information about your internal database, modify the diagnosticRepositoryDatabaseInfoCe MBean as follows:

<bean id=”diagnosticRepositoryDatabaseInfoCe” class=
“com.jaspersoft.jasperserver.api.logging.diagnostic.jmx.DiagnosticDynamicMBean”>
<property name=”diagnosticServices”>
<set>
<ref bean=”repositoryDatabaseInfo”/>
</set>
</property>
<property name=”excludedDiagnosticAttributes”>
<set>
<value>DatabaseProductName</value>
<value>DatabaseProductVersion</value>
<value>DriverName</value>
<value>SQLKeywords</value>
<value>URL</value>
<value>UserName</value>
<value>JDBCMajorVersion</value>
<value>JDBCMinorVersion</value>
<!–
<value>MaxRowSize</value>
<value>MaxStatementLength</value>
<value>MaxConnections</value>
<value>MaxCharLiteralLength</value>
<value>MaxColumnsInTable</value>
<value>MaxColumnsInSelect</value>
<value>MaxColumnsInGroupBy</value>
<value>MaxColumnNameLength</value>
–>
</set>
</property>
</bean>

•To exclude an entire bean, comment it out or remove it from the list of beans in the diagnosticExportingMBeansMap. For example, instead of excluding selected attributes, you could remove the entire repository database MBean as follows:

<util:map id=”diagnosticExportingMBeansMap” >
<entry key=”jasperserver:name=Users” value-ref=”${bean.diagnosticUsers}”/>
<entry key=”jasperserver:name=Reports” value-ref=”${bean.diagnosticReports}”/>
<entry key=”jasperserver:name=Scheduler” value-ref=”${bean.diagnosticScheduler}”/>
<entry key=”jasperserver:name=Settings” value-ref=”${bean.diagnosticSettings}”/>
<entry key=”jasperserver:name=Repository” value-ref=”${bean.diagnosticRepository}”/>
<entry key=”jasperserver:name=About” value-ref=”${bean.diagnosticJSAbout}”/>
<entry key=”jasperserver:name=HibernateStatics”
value-ref=”${bean.diagnosticHibernate}”/>
<entry key=”jasperserver:name=EhCache”
value-ref=”${bean.diagnosticEhCache}”/>
<entry key=”jasperserver:name=ExternalInfo”
value-ref=”${bean.diagnosticExternalInfo}”/>
<!–
<entry key=”jasperserver:name=RepositoryDatabase”
value-ref=”${bean.diagnosticRepositoryDatabaseInfo}”/>
–>
</util:map>

http://community.jaspersoft.com/documentation/jasperreports-server-administration-guide/v550/excluding-diagnostic-attributes

Disabling the Diagnostic Subsystem :

By default the JMX diagnostic subsystem is always enabled, but external access is password-protected and requires opening the diagnostic port in your firewall as described in Exposing Diagnostics Through Jaspersoft’s JMX Agent. If you wish to disable all external access, see Disabling Remote Connections to the JMX Agent.
Internally, the diagnostics subsystem is passive and has no performance impact until it is accessed in a report through the diagnostic data source. However, if you wish to disable the entire diagnostic subsystem, rename or remove the following files:

•applicationContext-diagnostic.xml
•applicationContext-diagnostic-pro.xml

http://community.jaspersoft.com/documentation/jasperreports-server-administration-guide/v550/disabling-diagnostic-subsystem.

Thanks & Regards

–A.Prasanth kumar.

Converting TimestampRange to Timestamp with default value expression and passing it into the Dataset .

 

Here when we are using our parameter class as net.sf.jasperreports.types.date.TimestampRange

with default value expression like

new java.sql.Timestamp((new Date()).getYear(), (new Date()).getMonth(),1,0,0,0,0)

then it will return (2016-01-01 00:00:00) format / Year /Month / Week/ Day.

new java.sql.Timestamp((new java.sql.Timestamp((new Date()).getYear(), (new Date()).getMonth(),(new Date()).getDate(),0,0,0,0)).getTime() + 86399000)

then it will return(2016-01-01 23:59:59) format / Year /Month / Week/ Day.

In this casse the default value will be in timestamp format so while extracting date from date range parameter

$P{P_StartDate}.getStart()

$P{P_EndDate}.getEnd()

we will get error.

So in this case we can get this timestamp format date in the variable of ireport or jasperstudio

we can create a variable and pass it to the SubDataset parameter by maping the variable of main report to subdataset or subreport and there we can use this timestamp value and pass it to our Query.

variable

Sql Query passing in jasper

column between $P{P_StartDate} and $P{P_EndDate}

If there are no default date ranges then we can pass a

$X{[BETWEEN], column, startParam, endParam}

If you want to set a relative date as a default value expression of a JasperReports parameter, use the following relative date-builder pattern:

  • new DateRangeBuilder(“DAY-1”).toDateRange()
  • new DateRangeBuilder(“WEEK”).set(Timestamp.class).toDateRange()
  • new DateRangeBuilder(“2016-01-01”).toDateRange()
  • new DateRangeBuilder(“2016-01-01 12:34:56”).toDateRange();

 

Thanks & Regards,

  Prasanth Kumar

Date Field Format Customisation in Adhoc View on Japser UI

Date Field Format Customisation in Adhoc View on Japser UI

Often while working with Adhoc Reports on jasper we get limited option for the availble date format in jasper. There are number of ways to fix this but one I am going to discuss here is by adding date format options in the backend of Jasperserver.

How we can add the different date formats in the Jasper UI itself is what I am going to describe in this blog. Here we are going to add the date format for “06/24/2016 11:15:25 a.m”.

1.First navigate to the path:
apache-tomcat\webapps\jasperserver-pro\WEB-INF\bundles\adhoc_masks.properties
where jasperserver is installed.
2. Open the file adhoc_mask.properties.
3. Edit the file content which appear somewhat like this:-

blog 1

4. Add “ADH_100_MASK_timestamp_5 = MM/dd/yyyy HH:mm:ss a” at required location.
5. In similar fashion we can customise the UI for the required date formats.
6. After making the changes save the file and restart the server. As new changes get reflected only after restarting the server.
7. Once the server gets restarted in the jasperserver you can notice the new option for date format by clicking on the date field in adhoc view, which we have just added in the backend file.

blog 2

Similarly we can edit the formatting of integer and decimal. Adding the format options in this way gives you more generalised approach to handle data formatting related tasks in jasper adhoc.

Thanks
Nisha Sahu

First encounter with Visualise.js

First encounter with Visualise.js

As we all know, visualise.js is a javascript framework introduced in JasperServer 5.6, for integration of jasperserver reports & visualizations inside web applications. It is available only with commercial editions of JasperServer 5.6.

Prior to 5.6, there were 2 methods for embedding, the simple HTTP/iframe integration method and the REST web APIs. The iframe way, though simple, did not give much control and limited branding options as it accesses the jasperserver UI itself from within the iframe. It however supports integration of Adhoc/Self service BI. REST APIs provided greater control, leverage to the repository services, greater control on the look and feel. However, it meant more coding, limited interactivity. Visualise.js leverages the REST APIs of jasperServer and provides a simple javaScript API, that could be easily used along with CSS to create webpages that seamlessly integrate interactive reports, with a few lines of code.

The API ranges from basic APIs for authentication, report rendering, resource search, accessing input controls to accessing/control of report events, errors, report hyperlinks. It also provides a way to interact with the JIVE UI components which provides a way to achieve higher interactivity.

After having a look at what visualise has to offer, lets see what it takes to embed a simple report using visualise.js. Below is a code snippet that shows a javascript code that renders a report into a div tag inside the webpage. This report takes one parameter, the store id.

HTML Page contents


<script type="text/javascript" src="http://localhost:8081/jasperserver-pro/client/visualize.js"></script>
<div id="container">Embedded a Sample Report</div>
<div id="testreport"></div>

JavaScript code using visualize.js

visualize({
    auth: {
        name: "joeuser",
        password: "joeuser",
        organization: ""
    }
}, function (v) {
  // Report API
    v("#testreport").report({
        resource: "/public/MyReports/Test1",
        params:{"storeid":["19"]},
        error: handleError
    });
    //showing Error
    function handleError(err) {
        alert(err.message);
    }
});

1. Loading the visualise.js script

<script type="text/javascript" src="http://localhost:8081/jasperserver-pro/client/visualize.js"></script>

This is the script tag which loads the visualize.js script from the location where it is present on the running instance of your JasperServer 5.6 (commercial edition).

2. A HTML container for the report
The division with ID “testreport” is the container for the report. This element will be passed to the visualize.js function when a report is rendered.

3. Authentication with JasperServer
Visualise is the function in visualize.js that establishes a connection with the JRS instance which hosts the report to be embedded. Its first parameter is an object which contains the configuration information required for connectivity – the URL of the JRS instance(server) and the authentication properties (auth).
The above example only shows authentication properties. The server URL is not provided, it internally takes the same server from which we requested the visualize script.

4. Rendering the report
The code for rendering the report is present in the callback function defined in the visualize call. ‘v’ is the client to the JRS instance for which session has been established.

v("#testreport").report({
        resource: "/public/MyReports/Test1",
        params:{"storeid":["19"]},
        error: handleError
 });

As can be seen, the selector to the container element in the html (#testreport) has been passed. The parameters are pretty self explanatory. “handleError” is a function which would handle any errors generated by report API.

5. Passing parameters to the report
As seen above, the “params” key in the argument to the report function is used to pass all the parameters to the report. The value has to be an array, even for single values to be passed.

And it is done !!

Hope this gives you basic understanding about visualise.js. A few more blog posts to follow, exploring other APIs of visualise.js. Till then, happy embedding !!

Imp References –
http://community.jaspersoft.com/wiki/visualizejs-api-notes-and-samples

– Shraddha
Helical IT Solutions

Create CrossTab In HDI(Helical Dashboard Insights) :

Creating CrossTab In Helical Dashboard Insight (HDI)

This blog will teach you how to create Cross Tab in HDI (Helical Dashboard Insights).

CrossTab uses PivotTable.js.Which is a JavaScript Pivot Table Library with drag and drop functionality. ‘PivotTable.js’ basic function is to turn a data set into a summary table and then optionally add a true 2-d drag’n’drop UI to allow a user to manipulate this summary table.

Main functions defined in ‘PivotTable.js’ is pivotUI()and is implemented as jQuery plugins.

PivotUI() takes 3 parameters :

1) Input : input is an array of objects, an array of arrays, a function or a jQuery object referencing a table.Here we are using Json Data as a input.

2) Option : is an object with the following keys:

  • aggregators: dictionary of generators for aggregation functions in dropdown, defaulting to common aggregators.
  • rows: array of strings, attribute names to prepopulate in row area, default is [ ]
  • cols: array of strings, attribute names to prepopulate in cols area, default is [ ]
  • vals: array of strings, attribute names to prepopulate in vals area, default is [ ] (gets passed to aggregator generating function)
  • aggregatorName: string, aggregator to prepopulate in dropdown (key to aggregators object), default is first key in aggregators .

3) Locale: is a string defaulting to en which controls the default locale for things like number formatting and error messages. Regardless of this setting, you can still override the default aggregators (which control number formatting) and error message strings. If this is set to something other than en you will have to load a locale-specific ‘language pack’ which creates this locale object before calling pivotUI().

For adding the Cross Tab in the HDI following steps should be followed:

1) EFW file: EFW contain the Title, author, description, Template name, visibility of the Dashboard.
2) HTML File:HTML file name should be the same that specified in the EFW file under the Template Section.
In HTML File On Top we specify links of the external link.
Here we are using the ‘PivotTable.js’ as external Library and it specified in the HDI as below:

<scriptsrc="getExternalResource.html?=CrossTab/PivotTable.js"></script>

We have to declare one CrossTab component in “CrossTab.html” file and in this component we need to provide the link of the file where the CrossTab chart property is defined.

3) EFWD File:EFWD file contain the Data Source Connection Properties such as connection id and connection type.It also contain Url of the connection to the database, User name and Password to the Database.

The DataSource Details used in our demo is shown as below:-

<DataSources>
        <Connection id="1" type="sql.jdbc">
           <Driver>com.mysql.jdbc.Driver</Driver>
           <Url>jdbc:mysql://192.168.2.9:3306/sampledata</Url>
            <User>devuser</User>
            <Pass>devuser</Pass>
        </Connection>
    </DataSources>

Data Map contains Map id and connection and connection Type. Map id is same as that specified in the EFWVF. Query for the Data Map and the Parameter to be used is specified in the Tags and Parameter in the Tags.

<DataMap id="2" connection="1" type="sql" >
       <Name>Query for CrossTab Component </Name>
		<Query>
			<![CDATA[
					SELECT distinct r.precinct,cd.candidate,sum(fact.votes) votes 
                                        FROM Voting_Summary as fact,region as r,contest as ct,candidate as cd 
                                        where fact.region_id=r.region_id and
                                        fact.contest_id=ct.contest_id and
                                        fact.candidate_id = cd.candidate_id 
                                        group by ct.contest,r.precinct,cd.candidate;

			]]>
              </Query>
</DataMap>

4)EFWVF File :-
In EFWVF file we first set the chart id the chart we set the chart properties. For Pie Chart we set the chart Properties between the tags. The properties such as Chart name, Chart type, Chart Data Source.
In Script we set the CrossTab as Below :

&ltscript&gt
		&lt![CDATA[											   				    
			    $(function(){
				$("#chart_1").pivotUI(data,
					    { 
						    rows: ["precinct"], 
						    cols: ["candidate"],
						    aggregatorName: "Integer Sum",
						    vals: ["votes"] ,
						   
					    }
					    );
			    });			    
						      
			]]&gt
		&lt/script&gt

By following these we are able to see the output which is as follows:
CrossTab

-By
Nitin Uttarwar
Helical It Solution

Create Table Component (Dynatable) in HDI (Helical Dashboard Insights) :

This blog will teach you how to Create Table Component (Dynatable) in HDI (Helical Dashboard Insights).

Dynatable : It is a library , it uses jQuery . It is a framework using which we can easily search ,   sort and filter the html tables data and data is in JSON Format.

Eg : –

<table>

<thead>

<th>name</th><th>class</th><th>address</th>

</thead>

<tbody></tbody>

</table>

And you ahve a record that looks like this:

{

“name”: “abc”,

“class”: “08-cs-08”,

“marks”: 72

}

Dynatable will render the “name” attribute to the first column, the “class” attribute to the second, and will ignore the “address” attribute since there’s no corresponding column header, and it will leave the last column blank since there’s not corresponding “marks” attribute.

By default, dynatable converts headings to JSON attribute names in camlecase . But we can change this by using the below property :

defaultColumnIdStyle:’underscore’

or

defaultColumnIdStyle: ‘lowecase’ etc.. 

To provide d3 dynatable feature in HDI , we need to go through following steps:

1. Database server – mysqlDB – foodmartTable : customerQuery :SELECT c.`customer_id` as customer_id, c.`account_num` as account_num, c.`fname` as fname, c.`lname` as lname, c.`address1` as address, c.`city` as city FROM foodmart.customer c;

The above information with username and password we need to provide in “demo.efwd” extension.

2.  We have to declare one dynatable component in “dynatable.html” file and in this component we need to provide the link of the file where the dynatable chart property is defined. 3.  In “dynaTable.efwvf” we need to define the dynatable properties and its link to database connection file i.e; “demo.efwd”

4.  One “dynaTable.EFW” file should also present which points to the template file i.e; “dynatable.html”

5.  Make all the three files in one folder and put              jquery.dynatable.css and jquery.dynatable.js file in the same folder and      give its path link in html extension file .

6.  By following these we are able to see the output which is as follows:

Capture2

Rupam Bhardwaj

Helical IT Solution

Overview of Jasper Server Authentication & Authorization

Overview of Jasper Server Authentication & Authorization

In JasperReports Server, access control is determined by two separate mechanisms, authentication and authorization.

  • Authentication is the process of verifying user credentials to give access to the server.
  • Authorization is the process of checking permissions granted to users and roles to access resources within the server.

Authentication

Authentication is the verification of a user’s identity to allow access to JasperReports Server. By default, anonymous access is disabled, and all users must present valid credentials to log in: a user ID, a password, and in certain cases an organization ID. Authentication is more than gathering the user credentials, it is a process that ensures that every page is secure, either viewed by a verified user or denied access until valid credentials are provided.

Jasper server supports following two types of authentication mechanisms:-

Internal Authentication (Default ):- DB based

internal_Auth

External Authentication:- process of gathering and verifying user credentials through a third-party application; for example:-

  • LDAP

Lightweight Directory Access Protocol (LDAP) is one of the most popular architectures for enterprise directories. By centralizing all user management in an LDAP directory, applications across the enterprise can share the same user database, and administrators do not need to duplicate user accounts in every application. LDAP authentication does not provide single sign-on (SSO) functionality.

LDAP

  • CAS

Central Authentication Service (CAS) is an open source, Java-based authentication server that includes a mechanism for single sign-on (SSO) across web applications, including those running on different application servers. When a user requests a page from a CAS-enabled web application, the application redirects the user to the CAS server login page. Thereafter, logged-in users can navigate between all participating applications without needing to log in again. Each application communicates with the CAS server in the background to verify that the user is valid before providing access to its resources.

CAS

Authentication happens only once at the beginning of the user’s session. After a user is authenticated, the user’s session is represented by an in-memory instance referred to as the principal object. The existence of the principal object determines that the user is logged on, and the user can access pages throughout the application. The principal object also stores the roles and organization ID of the user, which are required for authorization within JasperReports Server.

Authorization

Authorization is the verification of a user’s roles and organization ID to access features of the server, resources in the repository, and, in some cases, data. For every page that the user requests, the server determines which menu items, resources, and report contents the user can access, based on the principal object. Authorization happens every time a user accesses a resource.

In the JasperReports Server architecture, which is based on the Spring Framework and spring security authorization is always performed by internal mechanisms. Part of configuring external authentication is to define a mapping of external roles and organization IDs into the principal object so that authorization can proceed internally.

Authorization mechanism:-

  • In JasperReports Server, all resources are stored in the repository in a hierarchical structure of folders.
  • Each resource in the repository has a set of permissions explicitly granting certain kinds of access. Folders also have permissions, and all contents of a folder inherit these permissions if they do not explicitly define their own. Often, many resources need the same permissions, and therefore it is easier to manage permissions on folders.
  • Permissions can grant access to users or to roles. Roles are groups of users created for the purpose of simplifying authorization. Often, it is easier to manage permissions for groups of users, and then manage role membership separately. However, if necessary, permissions can be granted to specific users.

 

– By Archana Verma

Working with Crosstab Component In Pentaho Report Designer

This blog will teach reader about Working with Crosstab Component In Pentaho Report Designer

Crosstab is an experimental feature in Pentaho Report Designer . By default we can’t see crosstab component in PRD.

To enable this feature we need to do some modifications in Edit – > Preferences

1

In this Panel , go to “Other Settings” Tab and check the 2nd Option i.e, “Enable (unsupported) experimental features”.

Then Crosstab component will be automatically visible in PRD.

Data Source : JDBC : Sample Data Memory

Query :

2

If we will preview this query then we will get the data like below :

3

But In the above resultset it is very difficult to analyze the data .

So , its better visualization , I decided to create report with crosstab on this query .

Steps :

  1. Go to Master Report in Structure Tab
  2. On the right click of Master Report click on Add Crosstab Group

4

  1. Then you will find the below window

5

  1. Here you need to decide which field you want to see in row and which in column , accordingly set the fields you will get the output .

EXAMPLE :

6

Now Preview the report you will find something like below :

7

 

 

Rupam Bhardwaj

Helical IT Solutions

Using JavaBeans set Datasource in Jaspersoft iReport

JasperReports provides several types of pre-defined/ready-to-use datasources which can be used to provide the data that is filled in the report. We are going to look at one such datasource, the ‘JavaBeans Set Datasource’, which allows us to use JavaBeans as data to fill reports.

The basic idea is to provide 2 important things –

1. A JavaBean Class which defines the different fields of the datasource
2. A bean factory class which essentially returns a set of objects of the JavaBean class in form of an Array or Collection. Each object inside the array or the collection will be seen as one record in this type of data source.

We will now discuss each of these classes and how are they used in the datasource with an example.

1. Creating the Java Bean

The JavaBean Class is a Java class which exposes its attributes using “getter” methods. We define a “getter” method for every attribute which looks like public getXXX() , where XXX is the attribute in the class.
The example below, shows a WeatherBean Class which holds weather information for various cities. You can see a “getter” (accessor) method defined for each of the attributes as per the specified format.

/**
* Bean Class which defines that data structure and provides the getter methods 
*/
public class WeatherBean {
	private String cityName = ""; 
	private String weatherType = "";
	private int temperature = 0;

	public WeatherBean(String cityName, String weatherType, int temperature) {
	this.cityName = cityName;
	this.weatherType = weatherType;
	this.temperature = temperature;
	}

	public String getcityName() {
	return cityName;
	}

	public String getweatherType() {
	return weatherType;
	}

	public int gettemperature() {
	return temperature;
	}
}

2. Creating the bean factory class

The bean factory class should have a static method which will return a collection or an array of objects of the bean class. In the below example the method is getWeatherBeans().

import java.util.Collection;
import java.util.Vector;

/**
* Bean Factory Class which returns a collection of beans
*/
public class WeatherBeanFactory {

public static Collection getWeatherBeans(){
Vector allbeans = new Vector();
try {
allbeans.add(new WeatherBean("Delhi","Sunny",41));
allbeans.add(new WeatherBean("Mumbai","Cloudy",36));
allbeans.add(new WeatherBean("Bangalore","Rainy",28));
allbeans.add(new WeatherBean("Hyderabad","Sunny",39));
}
catch(Exception e){
e.printStackTrace();
}
return allbeans;
}
}

Export both the classes into a JAR file.

3. Add the JAR file to the iReport Classpath

jar-add-ireport

4. Create the JavaBean Set Datasource

Select the datasource type as “JavaBeans set datasource”

jar-add

Set the Factory class name and Static method call to retrieve the collection:
In our example, it is “WeatherBeanFactory” and “getWeatherBeans”

ds-1

5. Set the Report Query
Go to the “JavaBean” datasource tab. In class name, give the name of the bean class. In our example, its “WeatherBean”. Click “Read attributes” and select the fields as per your requirement.

rq-1

The mapping between a particular JavaBean property/attribute and the corresponding report field is made by naming conventions. The name of the report field must be the same as the name of the JavaBean property as specified by the JavaBeans specifications. For instance, to retrieve the value of a report field named cityName, the program will try to call through reflection a method called getcityName() on the current JavaBean object. This is how, it “getter” methods are used.
Below report is designed using the fields from the “WeatherBean” class.

rq-2

The output is shown below.

rq-3

Though we have used a simple JavaBean class, with attributes as basic types, Nested JavaBean properties can be also accessed in a JavaBean data source.

– Shraddha
Helical IT Solutions