Tuesday, April 29, 2014

NextReports: Generate an excel file based on existing template

NextReports 7.1 will introduce a new feature which will allow to generate an excel file based on one existing template file.

What does it mean? You may have an excel file with 2 (or more) sheets. One sheet is the actual data sheet and the others are computations made on values from data sheet like pivots for example.

Let's say you have a data sheet like:

and a pivot created on this data on a separate sheet:


This excel file is our template. By modifying data inside 'Data' sheet we will have by default this pivot in our resulted file. To make the pivot automatically refresh when we open the file, in the PivotTable Options dialog box, on the Data tab, select the 'Refresh data when opening the file' check box.

Now lets see how is this template used inside NextReports.

You create a simple report that prints the data in the form shown in 'Data' sheet. We have a simple query like:

 with a report showing just header and detail (no formatting needed):

Running such report as EXCEL will show us just a sheet (see previously Data sheet).

To specify that we have a template, some new properties were added on the Report node from layout tree:


 Here we can select a template excel file and the sheet number (starting from 1) where NextReports engine will write the data. In our example is sheet number 2. And that is all!

When you use some actions like Publish, Download from designer, the template file will be automatically passed between designer and server. On the server, when we do an upload, a new file upload field will allow to add a template. Also, Download and Edit in designer server actions will pass the template file to the client machine.


Tuesday, April 22, 2014

NextReports Survey

From some time ago, on NextReports site there is a small survey about the product. It can be found here.

From 7.1, to make people help us and also the entire NextReports open source community, we will show a small information about the survey on designer and server. This is not an intrusive message, once you click on the link or close the window, it will never show up again for that user.

Survey message will show after 10 days from installation, or , for server, if you use old data it may appear right away depending from how long logged user was created.

Inside NextReports Designer a small window will ask for taking the survey:


Inside NextReports Server a small message will notify the user on the top right corner:


If you want to contribute, please tell us on the survey wizard what are your needs.

Tuesday, April 08, 2014

NextReports: Images from database

NextReports Designer 7.0 allows to insert an image element to report layout. This element takes an image from a file. All images used by report are kept near that file, so when we publish a report to server from designer, all its images are also uploaded.

Starting with version 7.1 a new report layout element called "Image Sql Column" is added. This will indicate to report layout that at runtime to try to show the actual image that is kept inside database. Sql column must be of type blob or other specific image type used by different databases (for example MS SQL uses varbinary or image).

We create a query by selecting columns from a table (here Photo is our blob column):


When we run the query in designer we will see "blob"string for Photo values:


We create a report from this query:

Here we added instead a simple "Sql Column", an "Image Sql Column" for Photo:

This element has width and height properties to allow for image scaling.

Inside our database blob field we added different types of images (png, gif, jpeg) and a text file (to test if blob is not a recognizable image). When we export the report to PDF, EXCEL, HTML or RTF we will see actual images stored inside database:

Values that are not recognized as images, are seen with "blob" string.

Monday, March 24, 2014

NextReports: Creating a bubble chart

NextCharts can create a bubble chart from version 1.1. There are some minor differences between this chart and other types of charts.

First, the labels property uniquely identifies every bubble on the chart. You won't see the labels on X axis as on other charts, because values on X axis now have data meaning and must be computed similar with those on Y axis. Label values will be seen on tooltip if the template tooltip message contains a markup #label.

Second, the data property will contain exactly three arrays with values for X, Y and Z dimensions. These values can be seen in tooltip if #x, #val and #z markups are used.

Third, there is a new categories property with Strings that identify in which category falls every bubble. From this property the legend is computed (all unique categories). Category value can be seen inside tooltip if #c markup is used.

Let's create a bubble chart which shows the correlation between Life Expectancy (X), Fertility Rate (Y) and Population (Z) for a specific country (label) from a region (category).

JSON is like the following:
{"data":[[80.66,79.84,78.6,72.73,80.05,72.49,68.09,81.55,68.6,78.09],
         [1.67,1.36,1.84,2.78,2,1.7,4.77,2.96,1.54,2.05],
         [33739900,81902307,5523095,79716203,61801570,73137148,31090763,7485600,141850000,307007000]
        ],    
 "labels":["CAN","DEU","DNK","EGY","GBN","IRN","IRQ","ISR","RUS","USA"], 
 "categories":["North America","Europe","Europe","Middle East","Europe","Middle East","Middle East","Middle East","Europe","North America"],
 "color":["#004CB3","#A04CB3","#7aa37a"],                           
 "alpha":0.6, 
 "showGridX":true, 
 "showGridY":true,    
 "colorGridX":"rgb(0,198,189)", 
 "colorGridY":"rgb(0,198,189)", 
 "message":"#label< br >Life Expectancy: #x< br >Fertility Rate: #val< br >Region: #c< br >Population: #z", 
 "tickCount":4,
 "title":{"text":"Population Correlation", "font":{"weight":"bold", "size":14, "family":"sans-serif"}, "color":"blue", "alignment":"center"},
 "labelOrientation":"horizontal",         
 "type":"bubble",         
 "yData":{"font":{"weight":"bold","size":14,"family":"sans-serif"}, "color":"blue"},
 "xData":{"font":{"weight":"bold","size":14,"family":"sans-serif"}, "color":"blue"},
 "yLegend":{"text":"Fertility Rate","font":{"weight":"bold","size":14,"family":"sans-serif"}, "color":"#993366"},
 "xLegend":{"text":"Life Expectancy","font":{"weight":"bold","size":14,"family":"sans-serif"}, "color":"#993366"},
}
Result is the following chart:

When we move the mouse over a bubble element we will see all data defined in tooltip template message:


To use NextReports Designer (from 7.1 version)  to create such chart you must use a simple convention. You have to select on X axis the labels column (Country), and on Y axis you should add the four dimensions of the chart X, Y, Z and category (in this order).


Tuesday, March 11, 2014

NextCharts: Tooltip Messages

NextCharts can have a tooltip message with some markups that are automatically replaced at runtime. JSON property is called message.

The most important markup is #val which represents the actual value on Y axis. If you select for tooltip message Value #val you will see tooltips like in following chart:


Another markup is #x which represents the actual value of X label.
A message like #x<br>Value #val will show the following (here <br> markup is used to start a new line) :


Other markups have meaning just for specific chart types. For example, #total means the total value of all Y values and it has meaning for stacked bars, horizontal stacked bars and pie charts. A message like Category #x<br>Value #val from #total will show the following on a pie chart:


For pie charts there is another markup #percent which shows the percent from total of the current slice value. A message like Category #x<br>Value #val from #total<br>#percent% of 100% will show as:


To format actual Y value, if it is not a simple integer, you can use a JSON property like:
"tooltipPattern" : {
    "decimals": 2,
    "decimalSeparator" : ".",
    "thousandSeparator" : ","
}
From next version of NextReports (7.1) designer will have a new tooltip message property to allow customization like showing before, instead of some default values.

Tuesday, February 25, 2014

NextCharts: Combo Bar Line Charts

NextCharts supports bar and stacked bar combo charts. This means there can be more series inside a chart some bars / stacked bars, some lines.

A simple stacked bar json like:
{
   "type":"stackedbar",
   "style":"glass", 
   "data":[[16,66,24,30,80,52],[48,50,29,60,60,58],[30,40,28,52,34,50]],  
   "labels":["JAN","FEB","MAR","APR","MAY","JUN"], 
   "color":["#004CB3","#A04CB3","#7aa37a"],
   "legend":["2011","2012","2013"],
   "alpha":0.6, 
   "showGridX":true, 
   "showGridY":true, 
   "colorGridX":"rgb(0,198,189)", 
   "colorGridY":"rgb(0,198,189)", 
   "message":"Value #val from #total", 
   "tickCount":4,
   "title":{
        "text":"Financial Analysis",
        "font":{"weight":"bold", "size":16, "family":"sans-serif"},
        "color":"blue",
        "alignment":"center"
   },        
   "xData":{
        "font":{"weight":"bold", "size":14,"family":"sans-serif"},
        "color":"blue"
   },                          
   "yData":{
        "font":{"weight":"bold","size":14,"family":"sans-serif"},
        "color":"blue"
   },
   "xLegend":{
        "text":"Month",
        "font":{"weight":"bold","size":14,"family":"sans-serif"},
        "color":"#993366"
   },"
   "yLegend":{
        "text":"Price",
        "font":{"weight":"bold","size":14,"family":"sans-serif"},
        "color":"#993366"
   }
}
will look like:

To add combo lines (2 lines in this example)  we should add some properties to json object:
{
...
 "lineData":[[31.33, 52, 27, 47.33, 74.66, 53.33],[100, 120, 53, 190, 40, 130]],
 "lineColor":["#270283", "#CC6633"],
 "lineLegend":["Average", "Profit"],
...
}
With these, we obtain a combo chart like:


Friday, February 21, 2014

NextCharts: Styles

Styles are different ways to show a specific kind of charts. These are different for bar and line charts.
For bars these can be normal, glass, cylinder, parallelepiped and dome. For lines these can be  normal, soliddot, hollowdot, anchordot, bowdot, stardot.

Lets take a simple horizontal stacked bar chart:

1. normal
2. glass
3. cylinder
4. parallelepiped
5. dome

A simple line chart:

1. normal
2. soliddot
3. hollowdot
4. anchordot
5. bowdot
6. stardot

Thursday, February 20, 2014

NextCharts: A Developer Perspective

NextCharts is "the new kid in town" for NextReports Suite. It is a simple and nice HTML5 library,  created with Javascript and JQuery, which can be used by developers to show different types of charts.

Charts are drawn on a HTML5 canvas and tooltips are shown on a different canvas. Chart is passed as a JSON object. You can call the chart drawing function using as parameters the json and the ids of the two canvases:
nextChart(json, idCanvas, idTooltipCanvas)
In this case the chart will have the size of the canvas as specified inside CSS/HTML.

You can also specify the width and height in pixels or as percents:
nextChart(json, idCanvas, idTooltipCanvas, canvasWidth, canvasHeight)
A simple HTML page that shows a NextChart can specify (through css) how the tooltip will look. In this example there is a url that serves a json:
<html>
<head>

<title>NextReports Chart</title>

<style type="text/css">
  .tip {
    background-color:white;
    border:1px solid gray;
    border-radius: 5px;
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    position:absolute;
    left:-200px;
    top:100px;
  }
  
  .canvas {
   border: 1px solid gray;
  }
</style>

<script src="js/jquery-1.10.2.min.js" type="text/javascript"></script>
<script src="js/nextcharts-1.0.min.js" type="text/javascript"></script>
<script>

 $.ajax({
     type: "POST",
     url: "data-html5.json",
     contentType: "application/json; charset=utf-8",
     dataType: "json",    
     success: function(data) {
         console.log(data);
         nextChart(data, 'canvas', 'tip');
     },
     error: function(jqXHR, textStatus, errorThrown) {
         alert("Error: " + textStatus + " errorThrown: " + errorThrown);
     }
});     
</script>
</head>

<body>
    <canvas class="canvas" id="canvas" width="500" height="300"></canvas>
    <canvas class="tip" id="tip" width="1" height="25"></canvas>
</body>

</html>

Following we are taking about Json object structure. As a minimal set of characteristics, only the data and type properties are needed.
{
   "type":"bar",
   "data":[[16,66,24,30,80,52],[48,50,29,60,70,58],[30,40,28,52,74,50]],    
}
This will generate a bar series chart:

Type property can take a value from:  bar, stackedbar, hbar, hstackedbar, line, area, pie.

If you do not specify even type, then by default line is used.

Lets add some labels and change the colors:
{
   "type":"bar",
   "data":[[16,66,24,30,80,52],[48,50,29,60,70,58],[30,40,28,52,74,50]],
   "labels":["JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE"],
   "color":["#004CB3","#A04CB3","#7aa37a"]
}
Lets change the style and add some alpha to colors:
{
   "type":"bar",
   "data":[[16,66,24,30,80,52],[48,50,29,60,70,58],[30,40,28,52,74,50]],
   "labels":["JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE"],
   "color":["#004CB3","#A04CB3","#7aa37a"],
   "style":"glass",
   "alpha":0.6
}
Style property can have different values for different chart types. For bar charts it can be one of the following: normal, glass, cylinder, dome, parallelepiped. For line charts it can be: normal, soliddot, hollowdot, anchordot, bowdot, stardot.

Lets hide the grid and add a legend:
{
   "type":"bar",
   "data":[[16,66,24,30,80,52],[48,50,29,60,70,58],[30,40,28,52,74,50]],
   "labels":["JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE"],
   "color":["#004CB3","#A04CB3","#7aa37a"],
   "style":"glass",
   "alpha":0.6,
   "showGridX":false, 
   "showGridY":false,
   "legend":["2011 First year of work","2012 Second year of work","2013 Third year of work"]
}

Lets change labels fonts and colors and show a title:
{
   "type":"bar",
   "data":[[16,66,24,30,80,52],[48,50,29,60,70,58],[30,40,28,52,74,50]],
   "labels":["JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE"],
   "color":["#004CB3","#A04CB3","#7aa37a"],
   "style":"glass",
   "alpha":0.6,
   "showGridX":false, 
   "showGridY":false,
   "legend":["2011 First year of work","2012 Second year of work","2013 Third year of work"],
   "title":{
         "text":"Financial Analysis", 
         "font":{
              "weight":"bold", 
              "size":16, 
              "family":"sans-serif"
         }, 
         "color":"blue"
   },
   "xData":{
           "font":{
              "weight":"bold",
              "size":10,
              "family":"sans-serif"
           }, 
           "color":"blue"
   },
   "yData":{
           "font":{
              "weight":"bold",
              "size":10,
              "family":"sans-serif"
           }, 
           "color":"blue"
   }          
}

There are also other properties like:

tickCount: how many ticks are shown on y axis
message: message format for tooltip
tooltipPattern: a pattern for tooltip
background: background color
labelOrientation: x label orientation (horizontal, vertical, diagonal, halfdiagonal)
onClick: javascript function for click events

Friday, February 14, 2014

NextCharts: a new HTML5 library for NextReports

NextReports will reach a new version soon. A new year, a new major version. When I see 7.0 I have to say I am overwhelmed that NextReports starts its seven year. Looking behind, every release brought something new to make NextReports a tool for everyone. Evolution was not a process to push features just to have them (because others have), but a smooth and natural process to help our users needs.

NextReports 7.0 will bring a new chart library called NextCharts. It is a simple HTML5 library created to fulfill the needs of our open source product. Before it, NextReports used a flash library called OpenFlashCharts. It was a very good free library which served well our purposes. But because flash support is loosing  ground in recent software development, it was time for us to build from scratch a new HTML5 library which also allows for other OS smooth integration like Android systems. It became cumbersome to scratch your head on how to add flash plugin on some Android devices.

NextCharts will support all the features NextReports used in chart layout, no compromises were made. Starting from here, it will also allow us to grow the number of chart types. For version 7.0 you can have horizontal stacked bars, bar-line combos and stacked bar-line combos. Also stacked bars can have now any style as simple bars: normal, glass, cylinder, parallelepiped, dome.


Old flash support was not yet removed, because there are some places where technology is slowly introduced and modern browsers with HTML5 support are not available. That's why if your "dinosaur" browser does not understand HTML5, on NextReports Server you will automatically see a flash chart. (you need to have the flash plugin). That's why in designer you will have both HTML5 and flash previews.

NextCharts will fit as a glove for NextReports Server. From user perspective nothing is changed. Anyway, following is a glimpse on how the new charts look:


Choosing right colors makes the difference. Having just a black background for charts will create something quite different:


When user creates the chart in designer, he can choose to preview as HTML5, flash or image. If browser version is not a problem, users can forget about flash. Newer chart types do not have a correspondence to flash, so if you are stick with flash, you are stick with the old set of chart types.


Stay tuned! NextReports 7.0 is coming soon!

Friday, January 31, 2014

Deploy NextReports Server on JBoss AS 7.1.1

NextReports Server comes bundled with Jetty server as default. If you want to deploy NextReports Server to other web server you should at first read the special section found inside the manual.

For some servers it is very easy to do:
1. put the war in the deployment folder
2. register reports as web context
3. add reports folder to classpath.

For JBoss there are more things to do:

1. You should create a nextreports-server.war folder and unarchive the war file here (Just putting the war file in deployment it won't work)

2. Create an empty file called nextreports-server.war.dodeploy near nextreports-server.war folder (This is needed to inform JBoss to make the deploy of the exploded folder)

3. Add in web.xml from nextreports-server.war\WEB-INF :
   <context-param>      
        <param-name>resteasy.scan</param-name>
        <param-value>false</param-value>
   </context-param>

   <context-param>
         <param-name>resteasy.scan.resources </param-name>
         <param-value>false </param-value>
   </context-param>

   <context-param>
         <param-name>resteasy.scan.providers </param-name>
         <param-value>false </param-value>
   </context-param>
   These are needed because JBoss uses Resteasy as REST library while Next uses Jersey and these two are in conflict. So we deactivate Resteasy.

4. Current version 6.3 of Next uses an older version of Jersey library (1.7) You should use a newer version (1.18) From version 7.0 of Next the needed version of Jersey will be used by default. So replace the jersey jars from nextreports-server.war\WEB-INF\lib

5. Add following ehcache.xml in nextreports-server.war\WEB-INF\classes
<ehcache>
    <diskStore path="java.io.tmpdir"/>

    <cache name="org.hibernate.cache.UpdateTimestampsCache"
           maxElementsInMemory="50000"
           eternal="true"
           overflowToDisk="true"/>

    <cache name="org.hibernate.cache.StandardQueryCache"
           maxElementsInMemory="50000"
           eternal="false"
           timeToIdleSeconds="120"
           timeToLiveSeconds="120"
           overflowToDisk="true"
           diskPersistent="false"
               diskExpiryThreadIntervalSeconds="120"
           memoryStoreEvictionPolicy="LRU"
            />
    <defaultCache
            maxElementsInMemory="50000"
            eternal="false"
            timeToIdleSeconds="120"
            timeToLiveSeconds="120"
            overflowToDisk="true"
            diskPersistent="false"
            diskExpiryThreadIntervalSeconds="120"
            memoryStoreEvictionPolicy="LRU"
            />
</ehcache>

6. In nextreports-server.war\WEB-INF\classes\nextserver.properties modify  nextserver.home property as you wish.

7. In welcome-content folder from JBoss create reports folder (In this way reports is considered a web context). In server settings put this path to reports.home:  ../welcome-content/reports

Monday, January 20, 2014

NextReports Designer: Validate sql in version 7.0

NextReports Designer has a feature (action) which allows to validate queries, reports and charts regarding their query. Till 7.0 version, this validation only showed if something was wrong through a simple message and a warning icon inside browser tree.

From version 7.0, validation process will show as result what is wrong with the query (sql error message). If more queries are invalid, a list with all the errors is shown.


Validation process also takes care about parameters queries and sub-reports queries. This process does not show all errors from a single report (if there are more sql queries to test), but only the first.

This validation process becomes very useful if you have many reports / charts created on some database tables /columns and some table name or column name was changed. By using the replace button, you can automatically do a case sensitive or a case insensitive replace from designer.

Friday, December 13, 2013

NextReports: Creating the report programmatically

NextReports can be used to create a report programmatically. In our company, there was a need to have a report automatically created starting from a sql query and then run it using the engine api. Just think you have a set of data and a simple template which informs about layout properties (fonts, colors, padding and so on) and you want to bypass the process of creating a report using the designer.

To achieve this you have to create a Report object.
  Report report = new Report();
  report.setName("Report File Name"); 
  report.setSql("select ..."); 
  report.setLayout(createLayout(columnNames, "Title"));
The only thing you have to do is to create the ReportLayout:
 public static ReportLayout createLayout(List<String> columnNames, String title) {

        ReportLayout reportLayout = new ReportLayout();
        reportLayout.setReportType(ResultExporter.DEFAULT_TYPE);
        int size = columnNames.size();

        // create a row in header band with a title cell spanned on the entire row
        Band headerBand = reportLayout.getHeaderBand();
        List<BandElement> titleRow = new ArrayList<BandElement>();
        BandElement titleElement = new BandElement(title);
        titleElement.setColSpan(size);
        titleElement.setHorizontalAlign(BandElement.CENTER);
        titleElement.setVerticalAlign(BandElement.MIDDLE);
        titleElement.setPadding(new Padding(1,1,1,1));
        titleRow.add(titleElement);
        for (int i = 0; i < size - 1; i++) {
            titleRow.add(null);
        }
        List<List<BandElement>> headerElements = new ArrayList<List<BandElement>>();
        headerElements.add(titleRow);

        // create two rows in detail band: 
        // first with column names and second with ColumnBandElement cells
        Band detailBand = reportLayout.getDetailBand();
        List<BandElement> headerNamesRow = new ArrayList<BandElement>(size);
        List<bandelement> headerFieldsRow = new ArrayList<BandElement>(size);
        for (String column : columnNames) {
         BandElement he = new BandElement(column);
         he.setPadding(new Padding(1,1,1,1));
            headerNamesRow.add(he);
            BandElement ce = new ColumnBandElement(column);
            ce.setPadding(new Padding(1,1,1,1));
            headerFieldsRow.add(ce);
        }
        List<List<BandElement>> detailElements = new ArrayList<List<BandElement=>>();
        headerElements.add(headerNamesRow);
        detailElements.add(headerFieldsRow);
        
        // create an empty footer row
        Band footerBand = reportLayout.getFooterBand();
        List<List<BandElement>> footerElements = new ArrayList<List<BandElement>>();
        List<BandElement> footerRow = new ArrayList<BandElement>();
        for (int i = 0; i < size; i++) {
         footerRow.add(new BandElement(""));
        }
        footerElements.add(footerRow);

        headerBand.setElements(headerElements);
        detailBand.setElements(detailElements);
        footerBand.setElements(footerElements);               

        return reportLayout;
    }
  
This is the method used by "New Report" action from designer. You can choose any template properties to add on your BandElement cells.

After creating the report you can run it using the engine api or you can save it using  any ro.nextreports.engine.util.ReportUtil save methods.

Tuesday, November 19, 2013

NextReports Designer: View columns that have indexes

Even if NextReports Designer is a reporting tool and not a database tool, users asked to see what columns have indexes so they know if their queries are optimized or not.

From version 6.3 NextReports Designer will show indexed columns as an info icon

similar with those of primary keys and foreign keys. You can see this icon in "View Columns Info" action on any table:


You can also see this icon if you drag and drop a table in designer query perspective:

Monday, November 18, 2013

NextReports: Use reports to create portions of your web application

NextReports Server allows users to integrate charts & reports as iframes inside other applications using an embedded code.

If users do not want to use NextReports Server, there is also the possibility to use the generated reports inside iframes.

NextReports Server is implemented using Wicket framework. In Wicket , a simple document inline frame can be implemented to be used with an iframe tag inside html markup. This makes it very easy to use any Next report to show data from your database inside an application. After you have a NextReportPanel class like the one following, you do not need to write code to get particular data, you just have to create a report! and reuse this panel.

Lets say we want to see some report inside our web application.

The html file will look like:
<html>
    <wicket:panel>
        <iframe height="400px" wicket:id="report"></iframe>
    </wicket:panel>
</html>
Our Wicket component will be just a Wicket Panel. A ByteArrayResource just retrieves the report bytes which can also be cached if we want to. In this example we generate a HTML file:
public class NextReportPanel extends Panel { 
    private String reportName;
       
    // our object model (used to pass parameters to Next report)
    private Model model;
    
    // cache for report data per model
    private static Map<String, byte[]> dataMap = new HashMap<String, byte[]>(); 

    public NextReportPanel(String id, String reportName, IModel<String> model) {
        super(id);        
        this.reportName = reportName; 
        this.model = model;
        setRenderBodyOnly(true);
        add(new DocumentInlineFrame("report", new ReportResource()));
    }
    
    private String getModelId() {
        String id = "";
        if (model.getObject() != null) {
            id = model.getObject().getId();            
        } 
        return id;
    }    

    class ReportResource extends ByteArrayResource {
                
        private static final long serialVersionUID = -6307719094949487807L;
        private byte[] data;

        public ReportResource() {
            super("text/html");                    
        }
        
        @Override
        protected byte[] getData(final Attributes attributes) {            
            String id = getModelId();
            data = dataMap.get(id);            
            if (data == null) {                    
                data = generateReport();                
                dataMap.put(id, data);                
            }     
            return data;
        }                
        
        @Override
        protected void configureResponse(ResourceResponse response, Attributes attributes) {
            response.setCacheDuration(Duration.NONE); 
        }
              
        private byte[] generateReport() {            
            HashMap<String, Object> pValues = new HashMap<String, Object>();
            pValues.put("Id", getModelId());
            ByteArrayOutputStream output;
            Connection connection = null;
            Report report = getReport();
            try {
                output = new ByteArrayOutputStream();
                connection = ConnectionUtil.createConnection();
                FluentReportRunner.report(report).
                    connectTo(connection).
                    withQueryTimeout(60).
                    withParameterValues(pValues).
                    formatAs(ReportRunner.HTML_FORMAT).
                    run(output);                
                return output.toByteArray();
            } catch (Exception e) {
                LOG.error(e.getMessage(), e);
                return new byte[0];
            } finally {
                ConnectionUtil.closeConnection(connection);
            }
        }

        private Report getReport() {
            InputStream is = getClass().getResourceAsStream("/" + reportName);
            try {
                return ReportUtil.loadReport(is);
            } catch (LoadReportException e) {
                e.printStackTrace();
                return null;
            }
        }  
    }        
 }
This panel can be added in any page with different reports. To modify data (if users want to see more / less data) you will just have to modify the report! No source code modification!

Monday, October 21, 2013

NextReports: Search on google

In an older post we described what an External Drill is. What is not told there is that in  "Integration Settings" there is a property called "Drill Url". This is the base url used by all external links.

So we can set it for google web site:

Then, when we define an external  drill, we can put the relative url, in this case a search query for google site:

If no "Drill Url"is set inside "Integration Settings", the full url must be provided.

This means that inside our widget, when we click on second column (Employee):

 we will be redirected to a page with the results from google search:




Friday, October 11, 2013

NextReports: Some new things in 6.2 version

NextReports brings a few improvements in 6.2 version.

Cell formatting conditions allow to format that cell using an arbitrary expression value. Till now, only the value from that cell could be used.

You can see from the image above that user can choose between "Current value" of the cell and "Other value" which allows to enter an expression using any other report layout entities.

Report Layout can contain functions inside headers. Till now, functions could be added only in footers. So a rewritten Timesheet report for our demo will have the following layout :

and PDF result:

Server Alert definition can contain inside mail body the actual value for alarm or indicator. This must be specified through ${val} template string: