Welcome!

Java IoT Authors: Pat Romanski, Liz McMillan, Yeshim Deniz, Elizabeth White, Carmen Gonzalez

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
NHK, Japan Broadcasting, will feature the upcoming @ThingsExpo Silicon Valley in a special 'Internet of Things' and smart technology documentary that will be filmed on the expo floor between November 3 to 5, 2015, in Santa Clara. NHK is the sole public TV network in Japan equivalent to the BBC in the UK and the largest in Asia with many award-winning science and technology programs. Japanese TV is producing a documentary about IoT and Smart technology and will be covering @ThingsExpo Silicon Val...
SYS-CON Events announced today that Juniper Networks (NYSE: JNPR), an industry leader in automated, scalable and secure networks, will exhibit 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. Juniper Networks challenges the status quo with products, solutions and services that transform the economics of networking. The company co-innovates with customers and partners to deliver automated, scalable and secure network...
Grape Up is a software company, specialized in cloud native application development and professional services related to Cloud Foundry PaaS. With five expert teams that operate in various sectors of the market across the USA and Europe, we work with a variety of customers from emerging startups to Fortune 1000 companies.
Financial Technology has become a topic of intense interest throughout the cloud developer and enterprise IT communities. Accordingly, attendees at the upcoming 20th Cloud Expo at the Javits Center in New York, June 6-8, 2017, will find fresh new content in a new track called FinTech.
SYS-CON Events announced today that Interoute, owner-operator of one of Europe's largest networks and a global cloud services platform, has been named “Bronze Sponsor” of SYS-CON's 20th Cloud Expo, which will take place on June 6-8, 2017 at the Javits Center in New York, New York. Interoute is the owner-operator of one of Europe's largest networks and a global cloud services platform which encompasses 12 data centers, 14 virtual data centers and 31 colocation centers, with connections to 195 add...
In his keynote at @ThingsExpo, Chris Matthieu, Director of IoT Engineering at Citrix and co-founder and CTO of Octoblu, focused on building an IoT platform and company. He provided a behind-the-scenes look at Octoblu’s platform, business, and pivots along the way (including the Citrix acquisition of Octoblu).
SYS-CON Events announced today that CollabNet, a global leader in enterprise software development, release automation and DevOps solutions, will be a Bronze Sponsor of SYS-CON's 20th International Cloud Expo®, taking place from June 6-8, 2017, at the Javits Center in New York City, NY. CollabNet offers a broad range of solutions with the mission of helping modern organizations deliver quality software at speed. The company’s latest innovation, the DevOps Lifecycle Manager (DLM), supports Value S...
NHK, Japan Broadcasting, will feature the upcoming @ThingsExpo Silicon Valley in a special 'Internet of Things' and smart technology documentary that will be filmed on the expo floor between November 3 to 5, 2015, in Santa Clara. NHK is the sole public TV network in Japan equivalent to the BBC in the UK and the largest in Asia with many award-winning science and technology programs. Japanese TV is producing a documentary about IoT and Smart technology and will be covering @ThingsExpo Silicon Val...
@GonzalezCarmen has been ranked the Number One Influencer and @ThingsExpo has been named the Number One Brand in the “M2M 2016: Top 100 Influencers and Brands” by Analytic. Onalytica analyzed tweets over the last 6 months mentioning the keywords M2M OR “Machine to Machine.” They then identified the top 100 most influential brands and individuals leading the discussion on Twitter.
The 20th International Cloud Expo has announced that its Call for Papers is open. Cloud Expo, to be held June 6-8, 2017, at the Javits Center in New York City, brings together Cloud Computing, Big Data, Internet of Things, DevOps, Containers, Microservices 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 business opportunity. Submit your speaking proposal ...
The age of Digital Disruption is evolving into the next era – Digital Cohesion, an age in which applications securely self-assemble and deliver predictive services that continuously adapt to user behavior. Information from devices, sensors and applications around us will drive services seamlessly across mobile and fixed devices/infrastructure. This evolution is happening now in software defined services and secure networking. Four key drivers – Performance, Economics, Interoperability and Trust ...
The Internet of Things is clearly many things: data collection and analytics, wearables, Smart Grids and Smart Cities, the Industrial Internet, and more. Cool platforms like Arduino, Raspberry Pi, Intel's Galileo and Edison, and a diverse world of sensors are making the IoT a great toy box for developers in all these areas. In this Power Panel at @ThingsExpo, moderated by Conference Chair Roger Strukhoff, panelists discussed what things are the most important, which will have the most profound e...
Multiple data types are pouring into IoT deployments. Data is coming in small packages as well as enormous files and data streams of many sizes. Widespread use of mobile devices adds to the total. In this power panel at @ThingsExpo, moderated by Conference Chair Roger Strukhoff, panelists will look at the tools and environments that are being put to use in IoT deployments, as well as the team skills a modern enterprise IT shop needs to keep things running, get a handle on all this data, and deli...
With billions of sensors deployed worldwide, the amount of machine-generated data will soon exceed what our networks can handle. But consumers and businesses will expect seamless experiences and real-time responsiveness. What does this mean for IoT devices and the infrastructure that supports them? More of the data will need to be handled at - or closer to - the devices themselves.
SYS-CON Events announced today that Grape Up 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. Grape Up is a software company specializing in cloud native application development and professional services related to Cloud Foundry PaaS. With five expert teams that operate in various sectors of the market across the U.S. and Europe, Grape Up works with a variety of customers from emergi...
@ThingsExpo has been named the Most Influential ‘Smart Cities - IIoT' Account and @BigDataExpo has been named fourteenth by Right Relevance (RR), which provides curated information and intelligence on approximately 50,000 topics. In addition, Right Relevance provides an Insights offering that combines the above Topics and Influencers information with real time conversations to provide actionable intelligence with visualizations to enable decision making. The Insights service is applicable to eve...
DevOps is often described as a combination of technology and culture. Without both, DevOps isn't complete. However, applying the culture to outdated technology is a recipe for disaster; as response times grow and connections between teams are delayed by technology, the culture will die. A Nutanix Enterprise Cloud has many benefits that provide the needed base for a true DevOps paradigm.
Bert Loomis was a visionary. This general session will highlight how Bert Loomis and people like him inspire us to build great things with small inventions. In their general session at 19th Cloud Expo, Harold Hannon, Architect at IBM Bluemix, and Michael O'Neill, Strategic Business Development at Nvidia, discussed the accelerating pace of AI development and how IBM Cloud and NVIDIA are partnering to bring AI capabilities to "every day," on-demand. They also reviewed two "free infrastructure" pr...
New competitors, disruptive technologies, and growing expectations are pushing every business to both adopt and deliver new digital services. This ‘Digital Transformation’ demands rapid delivery and continuous iteration of new competitive services via multiple channels, which in turn demands new service delivery techniques – including DevOps. In this power panel at @DevOpsSummit 20th Cloud Expo, moderated by DevOps Conference Co-Chair Andi Mann, panelists will examine how DevOps helps to meet th...
Five years ago development was seen as a dead-end career, now it’s anything but – with an explosion in mobile and IoT initiatives increasing the demand for skilled engineers. But apart from having a ready supply of great coders, what constitutes true ‘DevOps Royalty’? It’ll be the ability to craft resilient architectures, supportability, security everywhere across the software lifecycle. In his keynote at @DevOpsSummit at 20th Cloud Expo, Jeffrey Scheaffer, GM and SVP, Continuous Delivery Busine...