Planet Jaspersoft

March 11, 2015

Software : 
Jasper Design Studio : 6.0.1 Pro
Jasper Server : 6.0.1 Pro

1) Calculating Percentage from java.lang.BigDecimal Types

By default all the numeric fields in report takes java.math.BigDecimal & you can not perform arithmetic  operations like division for calculating percentages. (Alternatively you need to work with the methods from BigDecimal class to get % kind of things)

Find percentage : 
1) Create a variable  of type java.lang.Double
2) Calculation = Nothing
3) Expression :
      $F{Field1}.doubleValue()/$F{Filed2}.doubleValue())*100  

    NOTE : $F{Field1} and $F{Filed2} are of java.math.BigDecimal types .
4) Increment type : None
5) Reset group :  If you are creating variables in any data set & using it in table component give your GROUP Name

6) Drag the variable on to the design area of table component.
7) Double click the variable to open it's  expression
     a) By default you can see it's expression as $V{Variable_1}
     b) Change the variable expression  to
              new DecimalFormat("#.##").format(Double.valueOf($V{Variable_1}))+"%"

2) Two decimal places after floating point for java.math.BigDecimal type values

  $V{Variable_2}.setScale(2, java.math.RoundingMode.HALF_UP)+"%"
This is on dragged variable. Not in the variable directly. The variable initially $V{Variable_2}. Double click it to get it's expression editor

Example: 95.83%

NOTE : 
a) Create a variable of double type for finding %'s .
                   i.e.,
                       Variable Name : VAR_PER_1
                      Expression :  (a.doubleValue()/b.doubleValue()) *100
                      Example : 95.834444123

b)  Now convert the above variable to Decimal type by creating a new variable of type Decimal
                 i.e., Variable Name : VAR_PER_2
                 BigDecimal.valueOf($V{VAR_PER_1})    [Remember it VAR_PER_1]

c) Now get 2 decimal places  by applying   $V{VAR_PER_2}.setScale(2, java.math.RoundingMode.HALF_UP)+"%"


3) Get only  Numeric value as percentage by rounding the decimal places of Double value

Assume you have java.lang.Double type having 45.45 and want to get 46 from it. Then the below expression will help full to you.

Variable_1=45.45                                              of java.lang.Double type
Variable_2= (int) ($V{Variable_1} + 0.5)        of java.lang.Integer type

[i.e., you need to create another variable of integer type and in its expression type cast the double variable to integer]

There could be another ways to solve the same kind of solutions using java expressions but I hope somehow the above tips help full.

Thanks for reading this page & suggestions and improvements to this page are welcome in comments box :-)

:-) SADAKAR POCHAMPALLI :-)
BI DEVELOPER, HYDERABAD, INDIA.

March 11, 2015

August 1, 2011

Short tutorial, shows how to schedule a report, how to change the way you are prompted for parameters and some basic editing of reports within iReport

August 1, 2011

April 18, 2011

This is a sysadmin how-to for backing up JasperReports Server (formerly JasperServer) and it's database (MySQL only for now).

I wrote a fairly robust script to achieve this task. It will read the database configuration from your default_master.properties file, work with several versions of JasperServer, delete old backups, write to the syslog and export the repository contents to file.

First drop my backup script into your \buildomatic folder if you're using 4.0 and abovie, 3.7 and below put in your /scripts folder.

Once the script is in place edit the variables at the top of the script:

This is to signify that you're using JasperServer 3.7.1 and below:
IS_PRE_4=false

This is a name for the product:
PRODUCT_NAME="JRS-4.0-Pro"

This is where backups will be stored:
BACKUP_DEST="/home/ernesto/Dropbox/Backups"

This will delete old backups if set to true
DELETE_OLD=true

How many days to keep old backups
DAYS=120

Now add it to your crontab. I will do it once a week in a lazy manner so will add the script to vim /etc/cron.weekly/js-backups

#!/bin/bash
/usr/local/jaspersoft/jasperserver4/buildomatic/js-backup.sh


The script will log to /var/log/messages:


The output files will look like this, I chose to stick them in my Dropbox folder for off-site backups:













You can download the script from this jasperforge forum post or view it below:

April 18, 2011

About

Planet Jaspersoft aggregates blog posts from our community. If you would like your blog to be included in the Planet, please follow this help guide. Or just click this link to go straight to your Planet Feeds.

Feedback
randomness