Welcome!

Java IoT Authors: Liz McMillan, Pat Romanski, Automic Blog, Elizabeth White, Roger Strukhoff

Related Topics: Java IoT

Java IoT: Blog Feed Post

BIRT Crosstab Scripting

The BIRT crosstab element offers onPrepare, onCreate and onRender hooks as well

BIRT supplies scripting hooks for just about every report element in the palette. You can generally implement an onPrepare, onCreate, and onRender event handler for each of these report items. The onPrepare event fires before data is retrieved and allows you to change the design for a specific report item. The onCreate event fires when the report item is being created by the report engine’s generation task. The onRender event fires when the report item is being rendered by the report engine’s render task. These events and example are described on the BIRT website.

Some report items offer more event hooks. For example a chart item actually has over thirty event hooks that allow total customization of the chart generation and presentation phases. As a side note, all chart scripts fire during the report engine’s render task. This does not mean the database is hit at render time though. The report engine will cache the data for a chart in memory or in a report document, depending on what task type is being used to run and render the report.

The BIRT crosstab element offers onPrepare, onCreate and onRender hooks as well. These events are fired both for the crosstab as a whole and for each individual cell in the crosstab. When firing events for cells, these are processed top to bottom and left to right. Handlers can be written using the script tab at the bottom of the report design view. BIRT also supplies an event adapter to allow you to write these events in Java as well.

As an example script, you can modify the crosstab in the onPrepare like:

function onPrepareCrosstab( crosstab, reportContext )
{
var coldim = crosstab.getColumnLevels().get(0);
coldim.removeAllFilterConditions();
crosstab.getStyle().setFontFamily("Arial");
crosstab.getStyle().setFontSize("8");

}

This script removes filters from the first column level and sets some font information. Some of the more interesting capabilities are available when using the onCreateCell event hook. For example consider the following script.

function onCreateCell( cellInst, reportContext )
{

//Can reference cells by type or id - valid types "header" or "aggregation"
if( cellInst.getCellType() == "header" ) {
//Get data values see binding tab on crosstab
//if( cellInst.getDataValue("PRODUCTLINE") == "Planes" ){
if( reportContext.evaluate("dimension['ProductGroup']['PRODUCTLINE']") == "Planes" ){
cellInst.getStyle().setBackgroundColor("#FF0000");
cellInst.getStyle().setFontSize("12");
}else{
//Set the rest to yellow
cellInst.getStyle().setBackgroundColor("#FFFF00");
cellInst.getStyle().setFontSize("12");
}

}
//refer to crosstab header
if( cellInst.getCellID() == 167){
cellInst.getStyle().setBackgroundColor("Orange");
}
if( cellInst.getCellType() == "aggregation"){
//Can refernce value using getDataValue or
if( cellInst.getDataValue("PRODUCTLINE") == "Planes" ){
//set color to bluegray
cellInst.getStyle().setBackgroundColor("RGB(169,170,226)");
}
//by using reportContext.evaluate
//if( reportContext.evaluate("measure['amount']") > 50000 ){
if( cellInst.getDataValue("amount_DateGroup/quarter_ProductGroup/PRODUCTLINE") > 50000 ){
cellInst.getStyle().setBackgroundColor("Green");
cellInst.getStyle().setColor("White");
}
}
}

The onCreateCell script is passed the reportContext and an instance of the cell. The cellInst object has several methods that can be used to determine which cell is currently being processed. You can call getCellType() which will return header or aggregation. In the following image all cells in the red box will return aggregation and all others will return header.

You can also call getCellID() which will return the specific element id that your crosstab uses for that cell.


In this example the getCellID call will return 160 every time this cell is created. This can be useful when you are trying to determine if you have a new row or column in your crosstab. If this is the innermost header element then this cell will be created for every new row/column. The only drawback to this approach is that if the crosstab is in a library or you copy and paste it, the cell ids will change.

Once you know the cell you are currently processing you generally want to access the data, to make some script decision. To do this you have a couple of choices. You can call the getDataValue method on the cell instance or use the reportContext.evaluate method. When using the getDataValue method, the value you need to refer to is the data binding column name set on the crosstab item. For example:

cellInst.getDataValue("PRODUCTLINE") == "Planes"

refers to the PRODUCTLINE data binding. Also note that this is the value of the column as this particular cell is being processed.

You can also use the reportContext.evaluate method, which allows you to build an expression and bypass the binding. For example:
if( reportContext.evaluate("dimension['ProductGroup']['PRODUCTLINE']") == "Planes" )

Essentially returns the same value as the previous getDataValue(“PRODUCTLINE”) method. This is because the PRODUCTLINE data binding has:

dimension['ProductGroup']['PRODUCTLINE']

As it’s expression. This example references a particular dimension of the cube. You can reference cube measures as well.

reportContext.evaluate("measure['amount']")

As with the column binding this will return the value for the specific cell you are currently processing.

In the script posted at the top of this post, we use the cell instance object to set specific styling based on the values of various column bindings. This is done using the getStyle method.

cellInst.getStyle().setBackgroundColor("Green");
cellInst.getStyle().setColor("White");

Using this method is no different than other BIRT report items.

Using these methods and the reportContext you can write some very sophisticated scripts. For example you can store all the quantities ordered where the product line is ships to a global variable using a script similar to this:

if( cellInst.getCellType() == "aggregation" && cellInst.getCellID() == 151){
if( cellInst.getDataValue("PRODUCTLINE") == "Ships" ){
importPackage(Packages.java.lang );
var cur = cellInst.getDataValue("amount_DateGroup/quarter_ProductGroup/PRODUCTLINE");
if( reportContext.getGlobalVariable("totalplanes")==null){
reportContext.setGlobalVariable("totalplanes", new Double(Double.parseDouble(cur)) );
}else{
var oldcnt = reportContext.getGlobalVariable("totalplanes");
reportContext.setGlobalVariable("totalplanes", new Double(Double.parseDouble(oldcnt) + Double.parseDouble(cur)));
}
}
}


This value can then be referenced within the same crosstab or later in the report. For example the following expression for a text item can be used.

<VALUE-OF format="#,##0.00">reportContext.getGlobalVariable("totalplanes");</VALUE-OF>

This example can also be implemented in Java. In the attached link the report will contain two crosstabs. One where the code is done in JavaScript and the other uses an event handler written in Java, which is also attached.

The example report output is presented below.



The examples are available at Birt-Exchange.

More Stories By Jason Weathersby

Jason Weathersby is a member of the extended BIRT development team at Actuate Corporation and has backgrounds in both computer science and technical writing. He has many years experience in technical consulting, training, writing, and publishing about reporting, business intelligence tools, and database technologies.

@ThingsExpo Stories
To get the most out of their data, successful companies are not focusing on queries and data lakes, they are actively integrating analytics into their operations with a data-first application development approach. Real-time adjustments to improve revenues, reduce costs, or mitigate risk rely on applications that minimize latency on a variety of data sources. In his session at @BigDataExpo, Jack Norris, Senior Vice President, Data and Applications at MapR Technologies, reviewed best practices to ...
In his Opening Keynote at 21st Cloud Expo, John Considine, General Manager of IBM Cloud Infrastructure, led attendees through the exciting evolution of the cloud. He looked at this major disruption from the perspective of technology, business models, and what this means for enterprises of all sizes. John Considine is General Manager of Cloud Infrastructure Services at IBM. In that role he is responsible for leading IBM’s public cloud infrastructure including strategy, development, and offering m...
"Digital transformation - what we knew about it in the past has been redefined. Automation is going to play such a huge role in that because the culture, the technology, and the business operations are being shifted now," stated Brian Boeggeman, VP of Alliances & Partnerships at Ayehu, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
Nordstrom is transforming the way that they do business and the cloud is the key to enabling speed and hyper personalized customer experiences. In his session at 21st Cloud Expo, Ken Schow, VP of Engineering at Nordstrom, discussed some of the key learnings and common pitfalls of large enterprises moving to the cloud. This includes strategies around choosing a cloud provider(s), architecture, and lessons learned. In addition, he covered some of the best practices for structured team migration an...
No hype cycles or predictions of a gazillion things here. IoT is here. You get it. You know your business and have great ideas for a business transformation strategy. What comes next? Time to make it happen. In his session at @ThingsExpo, Jay Mason, an Associate Partner of Analytics, IoT & Cybersecurity at M&S Consulting, presented a step-by-step plan to develop your technology implementation strategy. He also discussed the evaluation of communication standards and IoT messaging protocols, data...
Recently, REAN Cloud built a digital concierge for a North Carolina hospital that had observed that most patient call button questions were repetitive. In addition, the paper-based process used to measure patient health metrics was laborious, not in real-time and sometimes error-prone. In their session at 21st Cloud Expo, Sean Finnerty, Executive Director, Practice Lead, Health Care & Life Science at REAN Cloud, and Dr. S.P.T. Krishnan, Principal Architect at REAN Cloud, discussed how they built...
SYS-CON Events announced today that Evatronix will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Evatronix SA offers comprehensive solutions in the design and implementation of electronic systems, in CAD / CAM deployment, and also is a designer and manufacturer of advanced 3D scanners for professional applications.
SYS-CON Events announced today that Synametrics Technologies will exhibit at SYS-CON's 22nd International Cloud Expo®, which will take place on June 5-7, 2018, at the Javits Center in New York, NY. Synametrics Technologies is a privately held company based in Plainsboro, New Jersey that has been providing solutions for the developer community since 1997. Based on the success of its initial product offerings such as WinSQL, Xeams, SynaMan and Syncrify, Synametrics continues to create and hone inn...
"Evatronix provides design services to companies that need to integrate the IoT technology in their products but they don't necessarily have the expertise, knowledge and design team to do so," explained Adam Morawiec, VP of Business Development at Evatronix, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
With tough new regulations coming to Europe on data privacy in May 2018, Calligo will explain why in reality the effect is global and transforms how you consider critical data. EU GDPR fundamentally rewrites the rules for cloud, Big Data and IoT. In his session at 21st Cloud Expo, Adam Ryan, Vice President and General Manager EMEA at Calligo, examined the regulations and provided insight on how it affects technology, challenges the established rules and will usher in new levels of diligence arou...
Smart cities have the potential to change our lives at so many levels for citizens: less pollution, reduced parking obstacles, better health, education and more energy savings. Real-time data streaming and the Internet of Things (IoT) possess the power to turn this vision into a reality. However, most organizations today are building their data infrastructure to focus solely on addressing immediate business needs vs. a platform capable of quickly adapting emerging technologies to address future ...
In his session at 21st Cloud Expo, Raju Shreewastava, founder of Big Data Trunk, provided a fun and simple way to introduce Machine Leaning to anyone and everyone. He solved a machine learning problem and demonstrated an easy way to be able to do machine learning without even coding. Raju Shreewastava is the founder of Big Data Trunk (www.BigDataTrunk.com), a Big Data Training and consulting firm with offices in the United States. He previously led the data warehouse/business intelligence and B...
The 22nd International Cloud Expo | 1st DXWorld Expo has announced that its Call for Papers is open. Cloud Expo | DXWorld Expo, to be held June 5-7, 2018, at the Javits Center in New York, NY, brings together Cloud Computing, Digital Transformation, Big Data, Internet of Things, DevOps, Machine Learning and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding busin...
22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...
22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...
DevOps at Cloud Expo – being held June 5-7, 2018, at the Javits Center in New York, NY – announces that its Call for Papers is open. Born out of proven success in agile development, cloud computing, and process automation, DevOps is a macro trend you cannot afford to miss. From showcase success stories from early adopters and web-scale businesses, DevOps is expanding to organizations of all sizes, including the world's largest enterprises – and delivering real results. Among the proven benefits,...
@DevOpsSummit at Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, is co-located with 22nd Cloud Expo | 1st DXWorld Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The widespread success of cloud computing is driving the DevOps revolution in enterprise IT. Now as never before, development teams must communicate and collaborate in a dynamic, 24/7/365 environment. There is no time to wait...
Cloud Expo | DXWorld Expo have announced the conference tracks for Cloud Expo 2018. Cloud Expo will be held June 5-7, 2018, at the Javits Center in New York City, and November 6-8, 2018, at the Santa Clara Convention Center, Santa Clara, CA. Digital Transformation (DX) is a major focus with the introduction of DX Expo within the program. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive ov...
SYS-CON Events announced today that T-Mobile exhibited at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. As America's Un-carrier, T-Mobile US, Inc., is redefining the way consumers and businesses buy wireless services through leading product and service innovation. The Company's advanced nationwide 4G LTE network delivers outstanding wireless experiences to 67.4 million customers who are unwilling to compromise on qua...
SYS-CON Events announced today that Cedexis will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Cedexis is the leader in data-driven enterprise global traffic management. Whether optimizing traffic through datacenters, clouds, CDNs, or any combination, Cedexis solutions drive quality and cost-effectiveness. For more information, please visit https://www.cedexis.com.