Wednesday, February 29, 2012

NextReports: Some Internal Tips

From version 5.1, NextReports Designer allows to instantly open some report or chart  when it starts.

There are some system properties which can be used to achieve this:

next.datasource
This property is similar to singleSourceAutoConnect, but when we have more than one data source. NextReports Designer will start and it will connect to this datasource.

next.report 
If there is a connected data source (specified by next.datasource system property) this report will be auto-loaded.

next.chart
If there is a connected data source (specified by next.datasource system property) this chart will be auto-loaded.

next.path
If the report or chart is not found in the root node, but inside some folder, this property will specify the relative path.  Slashes or back-slashes can be used in any combination.

If both next.report and next.chart  system properties are specified, chart property is ignored. 

For your installed designer, you can specify system properties inside nextreports.vmoptions file.
For example adding these lines at the end of the file
-Dnext.datasource=Demo 
-Dnext.report=Timesheet
it will make your designer on start to auto-connect to Demo data source and to automatically open Timesheet report.

If your report is found inside /Test/Test1 folder path
-Dnext.datasource=Demo 
-Dnext.report=Timesheet
-Dnext.path=/Test/Test1
Path is converted to use specific file system separator, so you can enter it as you wish (/Test/Test1, Test/Test1, Test//Test1, \\Test\\Test1, Test\\Test1, \Test\Test1).

Thursday, February 16, 2012

NextReports: URL Custom Protocol & Version Dispatcher

When NextReports Server started its existence, users were able to upload reports and charts using server actions. This means:
  • a data source was already created
  • user selects the report from current location
  • user selects the existing data source
  • user selects the images used (if any) from current location
  • report/chart is uploaded in the current server path
After some versions, NextReports  Designer was able to allow publishing to server:
  • user selects server path
  • user selects a server data source; if there isn't created, he can publish it with a single click
  • when publish, used images are also published by default
Starting with version 5.1 a server action will allow to edit a report / chart with the designer:
  • no browsing needed
To allow this, a nextreports protocol is registered when NextReports Designer is installed. If this protocol is found, server edit action will open the designer asking for current logged user password:


After authentication, a data source is locally created (if not found) with following name convention:
<server_data_source_name>@<server_ip>
Designer will auto-connect to this data source and the report/chart is downloaded. If a report/chart with the same name exists, user is notified:


After downloading, the report/chart is automatically opened and user can start to edit it. When user saves it, a confirmation is needed to publish it also on the server:


Server 'Edit' action will launch an url request like:
nextreports://<server>?user=<loggeduser>&ver=<serverversion>&ref=<serverpathtoentity>
This can also be a simple  method to pass to someone a report to edit. If that person can access the report (has the needed rights) you do not need to tell him the server, location and let him download the report, modify it and publish it back. You just give him an url.

Specified version is used to open the needed designer which has the same version as the server avoiding following situations:
  • server version is older than designer version: you can download the report and edit it, but you cannot publish it to server
  • server version is newer than designer version: you cannot download the report
This is done by a dispatcher(installed with the designer) which is launched by nextreports URL protocol shell command.

If the designer with that version is not installed, user is informed and he can download the correct version from the links shown with the message:


If you are a Linux user, you do not have a dispatcher to start your needed version of NextReports, but you can register your nextreports url protocol with following commands:
gconftool-2 -t string -s /desktop/gnome/url-handlers/nextreports/command 
         '<installed_dir>/nextreports "%s"'
gconftool-2 -s /desktop/gnome/url-handlers/nextreports/needs_terminal false -t bool
gconftool-2 -s /desktop/gnome/url-handlers/nextreports/enabled true -t bool

Monday, February 06, 2012

NextReports: Variables, Functions & Expressions

NextReports has a simpler way of working with data, than other reporting solutions.

For example, inside iReport for JasperReports you can define a so-called variable just to use it in another fields. The problem with this approach is that the user must specify when this variable must be evaluated and when to be reset. (like page, report, group, column types). This is no easy task for non-business users who want to create some reports. This also can bring some invalid calculations if the user does not understand what he is doing.

NextReports does not have user-defined variables. In NextReports Variables are just application-defined like ROW, GROUP_ROW, PAGE_NO and so on.

Instead, users can create Expressions and Functions. Expressions can contain text, variables, parameters, columns and functions (from version 5.1). Functions can be any of SUM, AVERAGE, MIN, MAX, COUNT, COUNT DISTINCT and can be done on sql column or on expression.

For NextReports a field is evaluated if it is found inside layout. So, users do not need to ask themselves when to evaluate something. If you need an expression just to compute something without showing the result, you can make it hidden. But, you will always know when the expression is evaluated without asking yourself.

If we have two functions inside a group footer band

$F{SUM(HOURS)} : computes the sum of hours for a project (work, travel, administration, meeting)
$F{SUM(WORKHOURS)} : computes the sum of implementation hours

and we want also to see how much implementation represents in percentage, it is very easy to create an expression. From version 5.1 the user can select the functions found in the current band, in this case $F{SUM(HOURS)} and $F{SUM(WORKHOURS)}.


Report layout will show the defined expression:


Because functions are interpreted as double values the division will create a double. If you have an integer column $C_HOURS for example and you want to use div operations, be sure to convert it to double like $C_Hours.doubleValue(), otherwise the result will be an integer.


Result can be formatted with pattern property like in following exported pdf:



Wednesday, January 25, 2012

Page Header & Page Footer

A new feature will be included in NextReports 5.1 release: Page Header & Page Footer.

For document file exports like PDF and RTF, NextReports created page number in page header and current date in page footer. There was no way to define your header and footer data.

In 5.1 release, user will be able to define page header and page footer. Two new bands will be added to layout and they can contain any number of rows.



A new type of variable for page number can be inserted $V{PAGE_NO}. There is also the possibility to format page number as roman value:

Page number variable can also be inserted inside expressions like:


resulting in the following output:
 



Tuesday, January 17, 2012

Keep Settings inside Storage

Every application needs configuration. If configuration must be accessible by users of the application, then you have to persist all your properties.

NextReports Server kept its properties inside a property file. Some problems with a file approach are:
  • you must know where the file is located
  • after any modification it may be needed to restart the application
  • after any new version installation you need to copy your old property file

Starting with 5.0 version, server has a new Settings section visible by administrators. All settings are now kept inside JCR storage and the problems with the file approach were removed:
  • we know where the place to modify application settings is
  • after properties modification there is no need to restart the server (except for some that must be defined also in your web server configuration)
  • when a new installation (update) is done, by specifying the old storage path, you have by default all your previously settings


Settings are arranged by categories : general, thread pool, application look, jasper, synchronizer. Information or attention about properties are offered through tool-tips.  Only three properties require a restart of the server because you also have to modify something in your web server configuration files. These are:
  • Base Url: if you change this you maybe have to talk to your network administrator
  • Reports Home: “reports” folder must be in web server class path. For default Jetty server used, inside the installation folder you can find a start-nextserver.vmoptions file. In this file, the jetty class path is specified like this:         
    -Djetty.class.path=C:/Users/user.name/.nextserver/reports
  • Reports Url: “reports” folder must be mapped to a web context. This is needed because all generated reports have to be accessed through http URL links that look like the following:         
    http://<ip>:<port>/reports/<report_file>
           For Jetty server used by default, there is a contexts folder where you installed the server.
           Inside reports.xml file found here, there are two properties:
   /reports
   C:/Users/user.name/.nextserver/reports/
           which tell us that reports found at “resourceBase” on the hard disk can be served by the web server’s “contextPath”.

Monday, January 09, 2012

Know your date format

When it comes to date formatting, java makes use of SimpleDateFormat class:

"Date and time formats are specified by date and time pattern strings. Within date and time pattern strings, unquoted letters from 'A' to 'Z' and from 'a' to 'z' are interpreted as pattern letters representing the components of a date or time string. Text can be quoted using single quotes (') to avoid interpretation. "''" represents a single quote. All other characters are not interpreted; they're simply copied into the output string during formatting or matched against the input string during parsing."

When it comes to Jackrabbit internal, dates as saved to a specific format like the following string:
 2012-01-04T23:59:59.999+02:00
Taking forward to create the pattern for such a String results in:
yyyy-MM-dd'T'HH:mm:ss.SSSZ
Note that we need T not to be a pattern letter, so we unquoted it. We may think everything it's ok. If we need just to show a nice formatted date, we may not even see the difference. But if we want to use date formatted strings for some business, for example to do a Jackrabbit search of entities between two dates, we will found out (not easily) that the pattern is wrong.

Jackrabbit has a xs:dateTime function which has a formatted date as parameter. Obviously this date must have the same format used to store dates in Jackrabbit.

The problem with previously date format is the time zone, because there is no delimiter between the hours and the minutes, so the resulting string with SimpleDateFormat will be :
2012-01-04T23:59:59.999+0200
Because we cannot use a SimpleDateFormat string, we must use Jackrabbit api to format dates:
Calendar cal = Calendar.getInstance();
cal.setTime(date);
String formattedDate = ValueFactoryImpl.getInstance().createValue(cal).getString();

Thursday, December 22, 2011

A new look


The new look for NextReports site is finally done. It is easier to give feedback and it is easier to see what NextReports is about through the images carousel at the top. Perhaps new images will be added later. But for now, the general information is at the right place.

Wednesday, December 21, 2011

How to visually represent your actions in web applications

Inside any web application, sometimes you have to deal with a set of actions. There are many differences between how you represent your actions inside a web application and a desktop application.

For example, if we have a table with a set of actions which can be done for every entity shown in a row. In desktop applications, we may have a set of buttons near the table. In web applications this in not the case. We can represent actions like links inside table columns:

But this approach will soon become obsolete if the number of actions can rise in the following versions. To be scalable, we should use a menu of actions. This will allow us to have more and more actions as the application business grows:


If you have only a couple of actions, you can be easily convinced to represent them as simple links. For example, the widget panel from NextReports:


But in time, after application grows, not only this will be unaesthetic, but it can also break the view (see how the necessary space is not enough and the row of actions falls down):



A menu of actions will help us again and this will be the adopted solution in following version:


Summarizing, this will help us :
  • - not break the view
  • - make the interface more intuitive
  • - see what every action is about from start (not just on some tooltips)
  • - scale easily the number of actions
The only problem you may have with this approach is when you have a scroll involved and your actions menu is in the right side of your panel. In such cases, your popup will not be entirely shown (a horizontal bar will appear). To avoid such collision, you have to be sure you have enough space on the right to show the menu. See that we used the actions column not as the last one in the table or the actions image for a widget is put on the left of the toolbar, so everything will be ok.

Some other ways can be possible. Google, for example has a left-oriented menu, which ensures no collision with the scroll bar :

 
This can be done if you have a single actions link. But inside a table with such links on every row, this will be problematic because the menu will fall over the following links which must react on mouse-over events.

Tuesday, December 13, 2011

Spring 3 to the rescue

If you use Spring in your applications, you may need to pass some settings to a spring bean. Your settings can be defined in properties files, in system properties or inside an internal storage.

Let's say we want to use a property inside a spring bean like the following:
<bean id="myBean" class="com.mypackage.MyClass">
        <property name="myProperty">
            <value>${propertyValue}</value>
        </property>
</bean>

If propertyValue is defined inside a properties file we should define a propertyConfigurer bean:
<bean id="propertyConfigurer" 
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location">
            <value>classpath:myfile.properties</value>
        </property>
</bean>

If we want propertyValue to be overridden by system properties we can specify  systemPropertiesModeName :
<bean id="propertyConfigurer" 
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location">
            <value>classpath:myfile.properties</value>
        </property>
        <property name="systemPropertiesModeName">
            <value>SYSTEM_PROPERTIES_MODE_OVERRIDE</value>
        </property>
</bean>

If our settings   are defined inside a storage system (database, content repository), spring 3 will help us a lot with its new expression language SpEL. This allows for calling methods from a defined spring bean.

Lets say we have a settings bean like the following, were storageService  can be any storage you need:
<bean id="settings" class="com.mypackage.SettingsBean">
        <property name="storageService" ref="storageService"></property>
</bean>

SettingBean will offer us the propertyValue we need :

public class SettingsBean {
    
    private StorageService storageService;    
    
    public Settings getSettings() {
        return storageService.getSettings();
    }    

    @Required
    public void setStorageService(StorageService storageService) {
        this.storageService = storageService;        
    }
    
    // helper methods used in Spring with SpEL    
    public String getPropertyValue() {
        Settings settings = getSettings();
        return settings.getPropertyValue();
    }
}

With SpEL we can use the propertyValue in our bean like this:
<bean id="myBean" class="com.mypackage.MyClass">
        <property name="myProperty" value="#{settings.getPropertyValue()}"/>
</bean>

If the bean, which needs some settings from a storage, is a bean from the spring api, then it's very easy to set the properties using SpEL . Otherwise we would have had to extend that class to inject our storage. For example a Spring ThreadPoolTaskExecutor can be defined like this :

<bean id="schedulingTaskExecutor"
    class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
        <property name="threadNamePrefix" value="Scheduler-"/>
        <property name="corePoolSize" value="#{settings.getSchedulerCorePoolSize()}"/>
        <property name="maxPoolSize" value="#{settings.getSchedulerMaxPoolSize()}"/>
        <property name="queueCapacity" value="#{settings.getSchedulerQueueCapacity()}"/>
</bean>

Monday, November 21, 2011

NextReports Server - Dashboard Global Settings

Next version of NextReports Server will allow to select a 'Global Settings' action for dashboards.

This means we will be able to select some properties to all widgets from a dashboard. Two properties are always the same for any widgets: timeout and refresh time. Besides these two, if there are some common parameters used by all widgets, then those parameters can be also set .

Two parameters are considered the same if they have the same name, type, selection, manual source (if any),  default source (if any), and some properties like hidden property, procedure parameter, preview value. Some properties may be different, like runtime name, description or mandatory setting.


This 'Global  Settings' can be used for those dashboards which have a business of themselves, meaning  that some common parameters for more widgets are present.

Tuesday, November 01, 2011

NextReports Server : Drill Down Generalization

Previous versions of NextReports Server allowed to define a unitary drill down process. Charts could be drilled only to charts, tables could be drilled only to tables.

Version 4.2 makes a general approach to drill down. To link two widgets we have to specify :
  1. type of child widget (chart / table)
  2. link parameter
  3. column position whose value will be pass to the next report in the drill process (this will be shown only if the current widget in drill-down process is a table report)

 Drill-down entities will be seen as in previously versions inside a table, where column exists only if parent widget is a table report:



In this example we have a chart with two levels of drill down, first level is a table and second level is a chart.  This will be seen inside dashboard as passing through following widgets :





Friday, October 28, 2011

A bit of HTML, a bit of css and some iframes

To have a nice page with NextReports iframes is just a matter of html and css.

Tuesday, October 25, 2011

Wicket and AjaxFormComponentUpdatingBehavior


If you have a form component in wicket with some components and you want to change using ajax some things in that form before submit (when you click or edit on one of the components), then you have to use AjaxFormComponentUpdatingBehavior.

This is  a behavior that updates the hosting FormComponent via ajax when an event it is attached to is triggered.
private AjaxFormComponentUpdatingBehavior createAjax( ) {
     return new AjaxFormComponentUpdatingBehavior("onchange") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
          // do your task 
        }
     };
} 

The key is that your component must be a FormComponent, otherwise the event won't be triggered. Simple components like CheckBox, TextField, DropDownChoice are all FormComponents. But if you have a custom component create by yourself from more components  or even one like DateField, DateTextField , you will have to add a behavior to every sub-component to make your form update through ajax.

For example, a DateTimeField must respond if we change something inside its text field or if we change hours or minutes through its internal text fields, or AM/PM through its internal drop down choice. To access internal components from a wicket component we can use a get method with the markup-id as parameter if no methods are offered by that class. Inside DateTimeField we can override a newDateTextField method to add our behavior. But for the other elements we do not have similar methods, so we must look for the name of the markups in the html or java source code:
DateTimeField txtTime = new DateTimeField("txtTime", generalModel) {
     @Override
     protected DateTextField newDateTextField(String id,  PropertyModel dateFieldModel) {
        DateTextField f = super.newDateTextField(id, dateFieldModel);                  
        f.add(createAjax());               
        return f;
     }
}; 
// add ajax update behavior on hours and minutes textfields
txtTime.get("hours").add(createAjax());
txtTime.get("minutes").add(createAjax());


Friday, October 21, 2011

Java Enterprise in the Real World

Yesterday NextReports Team was a speaker at Oracle Java Developer Day in Bucharest. Our presentation "Java Enterprise in the Real World" can be seen here:

Friday, October 07, 2011

NextReports Server - New Dashboard Navigation


A new dashboard navigation was created for NextReports Server. The previously  list of dashboards was replaced with a simple table which is more robust allowing for a better management



To allow scalability for more-to-come actions on dashboards, the list of actions for every dashboard  was replaced with a popup menu accessible from right-arrow icon:


Default or selected dashboard has a special background color to see more clear were we are.

Regarding widgets, new animations with different effects are used for bars, lines and areas.


Tuesday, September 20, 2011

Area Charts

NextReports will bring support for area charts. These charts are useful for measuring performance (KPI). Implementation was straight-forward both with Open Flash Chart and JFreeChart.

Here's how an area chart with more series looks like in OFC:

The same Next chart generated with JFreeChart looks like:



One minor thing you must have in mind if you want to keep your colors unaltered is to paint the series in a Z-order, otherwise the colors will blend. This is not possible every time, so you must allow for color transparency. If there is no transparency, some areas won't be seen, which is not desirable.

See the same chart with blend colors in OFC:


and in JFreeChart:


In this case it is almost impossible to know which legend refers to some area. We must have at least a small portion of the area with the same color as in the legend. The best solution I can think of is to sort descending the areas from that which has the maximum value downwards and that will give as Z-order.

Tuesday, September 13, 2011

NextReports Server : Set dashboard as default

Inside NextReports Server any user can see a list of dashboards created by him or shared to him by other users. When the user logs-in he will see its personal dashboard 'My'.

In server 4.2 version, any dashboard will have a special action to set it as default (star icon). If no dashboard is set as default then 'My' dashboard is loaded at log in. If a dashboard is set as default then that dashboard will be loaded. If you follow only one dashboard in particular, this new feature will spare you the time of selecting it anytime you enter the application.

Friday, September 09, 2011

JDBC and Connection Timeout

If you want your jdbc driver connection not to wait more than a specified time even if the instance is down you may think that DriverManager.setLoginTimeout(seconds) is your friend. But if you test it with different drivers you will notice that for some it works and for some it does not.. So you are tight to the driver implementation which in many cases is not desirable.Given the fact that you can wait more than 30 seconds for a connection if the instance is down, it is imperative to look for alternatives.

The only general solution to this problem is to have a separate thread where you try to get the connection. You can set a timeout to complete the task of getting that connection. In java, FutureTask can be used to accomplish this:

Connection connection;
FutureTask task = null;
try {
    task = new FutureTask(new Callable() {
        @Override
        public Connection call() throws Exception {
            return DriverManager.getConnection(url, username, password);
        }
    });
    new Thread(task).start();
    connection = task.get(getConnectionTimeout(), TimeUnit.SECONDS);
} catch (Exception e) {
    throw new ConnectionException("Could not establish connection.", e);
}

Wednesday, August 24, 2011

Moving around with widgets

Version 4.1 of NextReports was out. We are looking now to the following 4.2 release.

A small, but important new feature will be the possibility to copy or move a widget from a dashboard to other dashboard. Do you have some nice dashboards with cool widgets and you want to make another dashboard and share it to other users? Now this task will be easier.

A new action "Copy / Move" can be found in the widget toolbar, before "Delete" :


This action allows to select your action (copy or move) and to execute it for the selected dashboard :


Wednesday, August 03, 2011

JColorChooser History

JColorChooser in java can be used to select a color from "Swatches", "HSB", "RGB" panels.  But only "Swatches" tab has a history of recent used colors. We want to have a global history for selected colors.

For that we have to add another panel in a JColorChooser (like ExcelPalette).  In java you have to create a new class which extends AbstractColorChooserPanel:
public class HistoryColorChooserPanel extends AbstractColorChooserPanel {          
         @Override
         protected void buildChooser() {    
                //  here you add your UI components
         }
}
To use it:
AbstractColorChooserPanel[] panels = chooser.getChooserPanels() ;
// create a new array of panels containing also your panel
chooser.setChooserPanels(newPanels);


Anytime a color is selected from any tab except "Color History", that color is added to history as the top-left color from the matrix, and all the other colors are moved by a cell to the right.

At first glance it does not seem a "big" functionality, but when you think you want to use a number of colors to make your reports and charts look alike, this will help you a lot of time instead of entering again and again the same colors.