Pages

Friday, May 10, 2013

how to use the logged in user in query with report designer and show user specific report.

Many times we need to design the reports which consist of data according to the user logged in. One can not show whole information to everyone, what we need to do is show the report accordingly. So here I am going to describe how to generate the report as per the user logged in.

         For getting information of user logged in we need ENVIRONMENT variable which are available from the release PRD 3.6. with the help of Environment variable we can get many information like Role, username, pentaho base url, server base url and so on. For more details on ENV variable available in PRD you can refer to these blog http://www.on-reporting.com/blog/access-session-and-environment/ and
and you can also refer to this video to get to know other details of Latest feature of PRD 3.6

Now I will take you through the details of how to use ENV variable env::username. First of all we need a database schema to make the report. I have made the schema usermaster having 3 tables:-
  1. user 
  2. products
  3. user_product_consumption
I am also providing you the create and insert MySQL query so that you will get the example easily without taking care of designing your own table.

create database usermaster;
use usermaster;

create table sampledata.user(userid int primary key,username varchar(45));

create table sampledata.products(productid int primary key,productname varchar(45));

create table usermaster.user_product_consumtion(id int primary key, userid int, productid int, foreign key (userid) references user(userid),foreign key (productid) references products(productid));

-- Insert user value

insert into usermaster.user values(1,'joe');
insert into usermaster.user values(2,'suzy');

--insert products value

insert into products values(1,'Milk');
insert into products values(2,'Coffee');
insert into products values(3,'Sugar');

insert user_product_consumption value

INSERT INTO `usermaster`.`user_product_consumption` (`id`,userid, `productid`) VALUES (1, (select userid from user where username='joe'), (select productid from products where productname='milk'));

INSERT INTO `usermaster`.`user_product_consumption` (`id`, `userid`, `productid`) VALUES (2, (select userid from user where username='joe'), (select productid from products where productname='coffee'));

INSERT INTO `usermaster`.`user_product_consumption` (`id`, `userid`, `productid`) VALUES (3, (select userid from user where username='joe'), (select productid from products where productname='sugar'));

INSERT INTO `usermaster`.`user_product_consumption` (`id`, `userid`, `productid`) VALUES (4, (select userid from user where username='suzy'), (select productid from products where productname='coffee'));

INSERT INTO `usermaster`.`user_product_consumption` (`id`, `userid`, `productid`) VALUES (5, (select userid from user where username='suzy'), (select productid from products where productname='sugar'));

Please note that for using env::username and to show the report according to the user logged in you should maintain the username same as available in Pentaho i.e. 'joe', 'suzy' etc. you can add your own username and give them different roles from Pentaho Administration Console as required. for details you can visit to the following link

Now back to the business, we will design report by 3 tables I have described above. First of all we will define the report query which is as follows :-
SELECT
     `user`.`userid`,
     `user`.`username`,
     `products`.`productid`,
     `products`.`productname`,
     `user_product_consumption`.`id`,
     `user_product_consumption`.`userid`,
     `user_product_consumption`.`productid`
FROM
     `user` INNER JOIN `user_product_consumption` ON `user`.`userid` = `user_product_consumption`.`userid`
     INNER JOIN `products` ON `user_product_consumption`.`productid` = `products`.`productid`
After Defining the query add  the parameter and give the values to the windows that appeared like parameter name, type, Default value formula, check the Hidden value and define the display type of parameter as Text box.
Default value formula should be like this ENV("username"). after doing this press ok, now you are done with defining parameter now rectify the query to use the parameter value. Add where clause to the report query and your final query should be like this:- 

SELECT
     `user`.`userid`,
     `user`.`username`,
     `user_product_consumption`.`id`,
     `user_product_consumption`.`userid`,
     `user_product_consumption`.`productid`,
     `products`.`productid`,
     `products`.`productname`
FROM
     `user` INNER JOIN `user_product_consumption` ON `user`.`userid` = `user_product_consumption`.`userid`
     INNER JOIN `products` ON `user_product_consumption`.`productid` = `products`.`productid`
     WHERE user.username= ${username}

After defining the query design the layout as required and save the report as "envdemo1.prpt". Now publish the report to the BI server by giving it the admin credential and launch the report from PRD and logged in as joe and then you will be able to view the joe's data only because you have logged in as joe.
              
            Now notice that if you will logged in as suzy you won't be able to view any data because suzy has no permission to access it. So log in as admin joe in PAC or PUC and right click on share and give all the rights to that user suzy by check the box all permission, now log in again as suzy and you will see the data of suzy.

For your better understanding follow the below video. :) 

Tuesday, April 30, 2013

Pentaho Report Integration in iframe

Camera Accessories. Free Shipping!


Ques:- Integrating pentaho report viewer into iframe

Integrating pentaho Report(published to BI server) can be done in google chrome browser but it can not be achieved in Mozilla Firefox and Internet Explorer for detail refer the issue at pentaho


But there is an alternative to achieve the desired and get through integration of report in iframe, as we all know the reporting url in pentaho looks something like this http://localhost:8080/pentaho/content/reporting/reportviewer/report.html?solution=steel-wheels&path=%2Freports&name=mainreport_steelwheels.prpt&locale=en_US&output-type=application/pdf in which report is shown in pentaho report viewer.
But due to pentaho report viewer issue with Firefox and IE we can not show the report in iframe, so what if we remove the reportviewer component. Lets do it:- remove the /reportviewer/report.html from your url. your new url will something look like this:- http://localhost:8080/pentaho/content/reporting/?solution=steel-wheels&path=%2Freports&name=mainreport_steelwheels.prpt&locale=en_US&output-type=application/pdf.
After doing this you will see you don't have any Export option in your report as it was in report viewer but don't worry you can have your own drop down list for Exporting. I will explain you how, see the last parameter in the url output-type which is defining the output-type of report, I am viewing as PDF, one can also view as HTML or RTF or excel. what we need to do is define a new drop down list and pass it's value to output-type.