Thursday, April 17, 2014

Jasper with Mongodb

Jasper with mongodb step by step. 

[ Mongodb not support the two tables/collection join but you can display two tables data in report by
Follow the below step one by one.]

Install MONGODB & Start MONGODB Server / Client

Download mongodb installation (mongodb-win32-x86_64-2.4.4.zip) and put in c:\ drive.

Open command prompt (cmd) and follow below steps.

Execute the below command to rename the folder name.

C:\>move C:\mongodb-win32-* C:\mongodb
C:\mongodb-win32-i386-2.0.6
1 file(s) moved.

Create mongodb default database directory
C:\>md data
C:\>md data\db

To Start the server execute below command.
C:\>cd mongodb\bin
C:\mongodb\bin>mongod

Open another command prompt (cmd) and start mongodb client.
C:\>cd mongodb\bin
C:\mongodb\bin>mongo

For more help of installation : http://docs.mongodb.org/manual/tutorial/install-mo...

Create Mongodb sample tables to understand in detail

Execute below all command in mongodb client  C:\mongodb\bin>mongo

Display all database command : show dbs
Create new database command :use test
db.createCollection("employee");
db.employee.insert(
{
_id: 1,
name: { first: 'John', last: 'Backus' },
city: 'New York',
department:1
}
);
db.employee.insert(
{
_id: 2,
name: { first: 'Merry', last: 'Desuja' },
city: 'London',
department:2
}
);
db.employee.insert(
{
_id: 4,
name: { first: 'Roman', last: 'Methyu' },
city: 'London',
department:1
}
);
db.employee.insert(
{
_id: 5,
name: { first: 'Roman', last: 'Roman' },
city: 'London',
department:2
}
);
db.createCollection("department");
db.department.insert(
{
_id: 1,
department: 'Manager'
}
);
db.department.insert(
{
_id: 2,
department: 'Accountant'
}
);

Create Mongodb Connection with Jasper

Create new connection and select MongoDB Connection.




Provide MongoURL and press test and save button.



mongodb://127.0.0.1:27017/test
Host Name : 127.0.0.1 (you can get the host Name number from mongodb server content).
Database Name : test 

Create Jasper Report

Step 1 : Report Main Query : { 'collectionName' : 'employee'}

Step 2 : Create Dataset : Employee
Create New Parameter : P_EMPLOYEE_ID
Employee Dataset Query :
{
'collectionName' : 'employee',
findQuery : {
$where : "this._id == $P!{P_EMPLOYEE_ID} "}
}

Step 3 :
Create Dataset : Department
Create New Parameter : P_DEPARTMENT_ID
Department Dataset Query :
{
'collectionName' : 'department',
findQuery : {
$where : "this._id == $P!{P_DEPARTMENT_ID} "}
}

Step 4:
Take two list control one for display employee data and second for display department data.

Output





To quick understanding use the below jasper report and run it

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report2" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="ireport.zoom" value="1.5"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<subDataset name="Employee">
<parameter name="P_EMPLOYEE_ID" class="java.lang.String"/>
<queryString language="MongoDbQuery">
<![CDATA[{
    'collectionName' : 'employee',
     findQuery : {
    $where : "this._id == $P!{P_EMPLOYEE_ID} "}
}]]>
</queryString>
<field name="_id" class="java.lang.Integer"/>
<field name="city" class="java.lang.String"/>
<field name="department" class="java.lang.Double"/>
<field name="name.first" class="java.lang.String"/>
<field name="name.last" class="java.lang.String"/>
</subDataset>
<subDataset name="Department">
<parameter name="P_DEPARTMENT_ID" class="java.lang.Double"/>
<queryString language="MongoDbQuery">
<![CDATA[{
    'collectionName' : 'department',
     findQuery : {
    $where : "this._id == $P!{P_DEPARTMENT_ID} "}
}]]>
</queryString>
<field name="_id" class="java.lang.Double"/>
<field name="department" class="java.lang.String"/>
</subDataset>
<subDataset name="dataset1"/>
<queryString language="MongoDbQuery">
<![CDATA[{ 'collectionName' : 'employee'}]]>
</queryString>
<field name="_id" class="java.lang.Double"/>
<field name="city" class="java.lang.String"/>
<field name="department" class="java.lang.Double"/>
<field name="name.first" class="java.lang.String"/>
<field name="name.last" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<detail>
<band height="26" splitType="Stretch">
<componentElement>
<reportElement x="0" y="0" width="299" height="26"/>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
<datasetRun subDataset="Employee">
<datasetParameter name="P_EMPLOYEE_ID">
<datasetParameterExpression><![CDATA[$F{_id}]]></datasetParameterExpression>
</datasetParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
<jr:listContents height="26" width="299">
<textField>
<reportElement x="0" y="0" width="100" height="26"/>
<textElement verticalAlignment="Middle" lineSpacing="Single"/>
<textFieldExpression class="java.lang.Double"><![CDATA[$F{_id}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="100" y="0" width="100" height="26"/>
<textElement verticalAlignment="Middle" lineSpacing="Single"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{city}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="200" y="0" width="87" height="26"/>
<textElement verticalAlignment="Middle" lineSpacing="Single"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{name.first}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
<componentElement>
<reportElement x="299" y="0" width="195" height="26"/>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
<datasetRun subDataset="Department">
<datasetParameter name="P_DEPARTMENT_ID">
<datasetParameterExpression><![CDATA[$F{department}]]></datasetParameterExpression>
</datasetParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
<jr:listContents height="26" width="195">
<textField>
<reportElement x="0" y="0" width="102" height="26"/>
<textElement verticalAlignment="Middle" lineSpacing="Single"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{department}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
</band>
</detail>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>

Monday, April 7, 2014

Jasper Server - Customize Theme

Jasper Server - Change Theme with company logo.

You can customize your existing Jasper Server Theme and login page as per your requirement.
Please follow the below steps for change Theme and customization.

1: Click on the Themes directory of the Jasper server where you can see the list of existing themes.

2: Right click on the theme (For example : defaults) which you want to change and press Download the theme option.

3: Give the name to the downloaded theme and save it in your computer.

4: Right click on the Theme folder in Jasper server and select Upload a Theme option.

5: Browse the same compress file (.zip) which you have downloaded with different name.
How to modify the company logo/theme.

1. To upload a new logo click on your theme which you have just uploaded and select images sub directory,
here you can find all the images which are currently being used by theme.

2: Search for the logo.png image in images and edit the image, and upload your company logo but logo should be the same in dimension of JasperSoft logo.
(Logo dimension should be 141* 28 in pixels)

3: Just right click on the new theme and select Set as Active Theme option.
Now you can see new company logo in place of the JasperSoft logo.

4: You can also change the main login page image, click on the your theme which you have just uploaded and select images
sub directory, here you can find all the images which are currently being used by theme, search for the
login_welcome_ce_bkgd.jpg and edit the image and upload your image (image size 669*283 in pixels)




Tags: 

Jasper Server
Customize Theme
Change company logo
Customize Jasper Server Log-in page