Monday, October 12, 2015

Customizing Pentaho Report Web viewer

Hi Friends,

We can customize the Pentaho report Web viewer  (Open .prpt report in New Window  after Publishing)

Usually we will get window something like below for Example:



But the client requested me to customize this viewer with below requirement.

1. By default the panel should be hidden
2. Auto-submit option should be invisible


To customize this viewer, We have to edit a file  called report.html that is available in the installation folder structure:

C:\Pentaho\server\biserver-ee\pentaho-solutions\system\reporting\reportviewer

In the above path we will have a file with name : report.html


Here I did not remove any code that is available in the file and I have just done some trick to achieve mentioned requirements.

We start with second requirement, We can set this at report designer level by selecting Master-Report
and set false to "Auto-submit".

Now to implement the firest requirement I have used below code:

require(['dojo/ready', 'reportviewer/reportviewer-app'], function(ready) {
      ready(function(){
        dojo.addOnLoad(function(){
          require(["dojo/query"], function(query){
            /* function tryHide(isHide){
              var autoComplete = $('#reportControlPanel label.auto-complete-checkbox');

              if(autoComplete.length>0){
                if(isHide)autoComplete.hide();
              }else{
                setTimeout(function(){tryHide(isHide)},100);
              }
            }*/

function loadReportOnLoad() {
if ($('#reportControlPanel .pentaho-button').length > 0) {
$('#reportControlPanel .pentaho-button').click();
                $(".dijitToggleButton>.dijitButtonNode").click();
 } else {
                 setTimeout(function(){loadReportOnLoad();},100);
 }

}
            //tryHide(true);// control hide/show autocomplete
loadReportOnLoad();
          });
        });
      });
    });



After adding the above code to the file, report viewer will looks like below sanp shot:







After Modification, you file should be something like below code:



<!DOCTYPE html>
<html xmlns:pho="http:/www.pentaho.com">
<head>
  <title>Report Web Viewer</title>

  <link rel="shortcut icon" href="images/favicon.ico" />

  <!-- Include CDF styles first to make sure they can be properly overridden -->
  <link rel="stylesheet" href="../../../content/pentaho-cdf/js-legacy/cdf.css" type="text/css" />

  <link rel="stylesheet" type="text/css" href="../../common-ui/resources/web/dojo/dijit/themes/pentaho/pentaho.css"/>

  <script type="text/javascript" src="webcontext.js?context=reporting"></script>

  <link rel="stylesheet" href="../../../content/pentaho-cdf/js-legacy/lib/jdMenu/jquery.jdMenu.css" type="text/css" />
  <link rel="stylesheet" href="../../../content/pentaho-cdf/js-legacy/lib/jdMenu/jquery.jdMenu.slate.css" type="text/css" />
  <link rel="stylesheet" href="../../../content/pentaho-cdf/js-legacy/lib/impromptu/jquery-impromptu.css" type="text/css" />

  <link rel="stylesheet" type="text/css" href="../../../content/common-ui/resources/web/dojo/dijit/themes/pentaho/pentaho.css"/>
  <link rel="stylesheet" href="../../../content/common-ui/resources/web/prompting/pentaho-prompting.css" type="text/css" />
  <link rel="stylesheet" href="../../../content/reporting/reportviewer/reportviewer.css" type="text/css" />

  <style>
  #reportControlPanel label.auto-complete-checkbox {
    display:none;
  }
  </style>

  <script type="text/javascript">

    var _isReportViewer = true;
    var _isTopReportViewer = true;
    try { _isTopReportViewer = ((window.parent === window) || !window.parent._isReportViewer); } catch(ex) { } // Ignore "Same-origin policy" violation in embedded IFrame
   
    var inMobile = false;
    try {
      var ua = navigator.userAgent;
      inMobile = ua.match(/iPhone/i) || ua.match(/iPod/i) || ua.match(/iPad/i) || ua.match(/Android/i);
    } catch(ex) { /*XSS*/ }

    var dojoConfig = {
      parseOnLoad: false,
      isDebug: true,
      disableFlashStorage: true
    };



    /**
     * This is called when a gwt module has been loaded. We depend on these so we'll defer loading of functionality until
     * modules have been loaded.
     */

    var gwtModuleLoaded = function(moduleName) {
      if (moduleName === 'formatter') {
        // Once the GWT JSTextFormatter is loaded we can depend on other modules we need and then load the report viewer

        require(['local'], function(local) {
          local.define('formatter');
        });

      }
    };


    try {
      if(window.top.showLoadingIndicator) {
        window.top.showLoadingIndicator();
      } else if(window.parent.showLoadingIndicator) {
        window.parent.showLoadingIndicator();
      }
    } catch(ex) { } // Ignore "Same-origin policy" violation in embedded IFrame
  </script>
  <script type="text/javascript" src="../../../content/common-ui/resources/web/formatter/formatter.nocache.js"></script>

  <script type="text/javascript">
    // Provide somewhere for cdf/simile/ajax/scripts/json to inject itself into
    var SimileAjax = {};

    var logger, logged;


    require(['dojo/ready', 'reportviewer/reportviewer-app'], function(ready) {
      ready(function(){
        dojo.addOnLoad(function(){
          require(["dojo/query"], function(query){
            /* function tryHide(isHide){
              var autoComplete = $('#reportControlPanel label.auto-complete-checkbox');

              if(autoComplete.length>0){
                if(isHide)autoComplete.hide();
              }else{
                setTimeout(function(){tryHide(isHide)},100);
              }
            }*/

function loadReportOnLoad() {
if ($('#reportControlPanel .pentaho-button').length > 0) {
$('#reportControlPanel .pentaho-button').click();
                $(".dijitToggleButton>.dijitButtonNode").click();
 } else {
                 setTimeout(function(){loadReportOnLoad();},100);
 }

}
            //tryHide(true);// control hide/show autocomplete
loadReportOnLoad();
          });
        });
      });
    });
  </script>
</head>

<body class="tundra body contentHidden">
<div id="toppanel" class="pentaho-transparent hidden">
  <div id="toppanelinner" >
    <div id="toolbarlinner2" class="pentaho-rounded-panel2-shadowed pentaho-padding-sm pentaho-shine pentaho-background">
      <div id="toolbar" data-dojo-type="dijit.Toolbar">
        <div id="pageControl" data-dojo-type="pentaho.common.PageControl" class="dijitInline"></div>
        <span id="toolbar-parameter-separator" data-dojo-type="dijit.ToolbarSeparator"></span>
        <div id="toolbar-parameterToggle" data-dojo-type="dijit.form.ToggleButton" iconClass="dijitEditorIcon dijitEditorIconParameters" showLabel="false">Parameters</div>
      </div>
    </div>
    <script type="text/javascript">
      if(inMobile) {
        document.getElementById('toolbarlinner2').innerHTML =
            '<div id="toolbar" style="display: -webkit-box">' +
                '<div id="toolbar-parameterToggle" data-dojo-type="dijit.form.ToggleButton">Prompts</div>' +
                '<div style="display: -webkit-box; -webkit-box-flex: 1; box-sizing: border-box; -webkit-box-align: center; -webkit-box-pack: center;">' +
                '<div id="pageControl" data-dojo-type="pentaho.common.PageControl" class="dijitInline"></div>' +
                '</div>' +
                '<div style="visibility: hidden" data-dojo-type="dijit.form.ToggleButton">Prompts</div>' + // TODO: What is this? A second button?
                '</div>';
      }
      // document.getElementById('toolbar-parameterToggle');
      var inSchedulerDialog = window.location.pathname.toLowerCase().indexOf('parameterui') >= 0;
      var getParams = function() { return prompt.panel.getParameterValues(); };

      var initSchedulingParams = function(filePath, validParamsCallback) {
        this.file = filePath;
        this.parameterValidityCallback = validParamsCallback;

        // We're not valid until the prompt is refreshed and tells us we are
        if (this.parameterValidityCallback) {
          this.parameterValidityCallback(false);
        }
      };
    </script>
    <div id="reportControlPanel" class="hidden pentaho-rounded-panel-bottom-lr pentaho-shadow">
      <div id="promptPanel" class="pentaho-rounded-panel-bottom-lr"></div>
    </div>
  </div>
</div>

<div id="reportArea" class="pentaho-transparent">
  <div id="reportPageOutline">
    <iframe id="reportContent" frameborder="0"></iframe>
  </div>
</div>

<div id="messageBox" data-dojo-type="pentaho.common.MessageBox" title="" style="width:400px; display:none;">
</div>
<div id="glassPane" data-dojo-type="pentaho.common.GlassPane">
</div>
</body>
</html>





Backing up Pentaho Server during Crash time.

Backing up the files of the Pentaho Suite:

NOTE: You must quit all Pentaho programs and stop all Pentaho-related services (including the BA Server, DI Server, Pentaho Enterprise Console, and the solution database) before creating backups. Do not start the services backup until it is complete

The easiest way to back up a directory is to create a compressed archive of it. 
  •  Generally on a Windows system you would use the Zip or RAR formats through programs like 7-zip or WinRAR.
  • On Linux, BSD, and Solaris, you would use GNU Tar or bsdtar.

No matter which program you use, you should end up with either one single file that encompasses the entire /pentaho/ directory (for graphical installer and archive deployments), or the /pentaho/ directory plus the pentaho.war file from your application server (for manual deployments).

Backing up the Pentaho Repository:

Using whatever tool you choose depending on your DB (Oracle, MySQL, or PostgreSQL).   Run a backup of the 'Hibernate' and 'Quartz' DB's/Schema's.   


If you have a backup of the /pentaho directory and the DB, you should be able to restore your system.   As to a backup schedule, that is completely up to you and your infrastructure requirements.

Backup of Pentaho 5.x
Steps for taking backup of the content
  1. Log in to the operating system of the server machine as the user that installed Pentaho 5.0.0. Using this user is important to avoid any issues with operating system file permissions.
  2. Stop the Business Analytics server.
  3. Take a complete database backup of the quartz, hibernate, and jackrabbit databases. If you're using Postgresql, use the command-line tool pg_dump in the postgresql bin folder. You will need to authenticate as the main database user for each database (jcr_user for jackrabbit, hibuser for hibernate, and pentaho_user for quartz). For example (from the command-line) - for the jackrabbit database:
"C:\Program Files\pentaho\postgresql\bin\pg_dump" -U jcr_user jackrabbit > %TEMP%\jackrabbit.dmp (Windows)
Or
postgresql/bin/pg_dump -U jcr_user jackrabbit > /tmp/jackrabbit.dmp (*nix)
If you're not using Postgresql, please use the tools provided by your database vendor to take full backups of those databases
4. Take a backup of full bi-server directory.
You can also use the import-export utility to backup content only
Follow the link below to Upload and Download from the BA Repository, Using the import-export utility Download the content to backup.

Data cache in Pentaho Report designer.

Hello Friends,

There might be situation where your Data source has been updated and your report still shows old data values.

For this again you need to login to Pentaho enterprise console and manually refreshing "Report Data".


How ever this is not possible every time and End user also not understand this.


So to avoid this, We have to make it fix at report designer level it self.

How we do that:

1. Open your report
2. Select Master Report
3. Go to Attributes and set "False" to   data-cache

Now your report will be able to show updated data from the data source. 

How to read images from database in Pentaho Report designer

Hello Friends,

If you want to display images that are stored in the database, then we have a component called "Image-Field" on existing tool kit at left side of the PRD work space.


Drag "Image-Field" to the work space and navigate to  "Attributes" section and select value for "Field".


If you have multiple images to be display then use the "subreport" concept and drag and drop this image filed to the details section and have multiple images to your report.




Set Dynamic Height to data in the Details Section - Pentaho Report

Hello guys,


If you are facing issues with alignments, here is a simple trick.

select all the fields available in the details section and  go to styles and make height as 100% (Adjust according to your requirement)

Do not forget to add % at the end.

So that if data for a particular field is more than we set before, now height will adjusted automatically with out having breaks on borders.




Passing Dynamic IP address in Pentaho Drill down Reports

Hi Friends,

I am going to explain today about how to specify dynamic IP address in pentaho drill down reports.


For example, I have a Parent-report.prpt and child-report.prpt, Now If I want to create drill down from Parent report to child report. we have to use the drill down function where we manually browse the Child report.

Once you manually browse the child report the drill down function looks like below function:


=DRILLDOWN("remote-sugar"; "http://192.168.10.104:8081/pentaho"; {"country"; [COUNTRY] | "::pentaho-path"; "/public/TEST/sub-report.prpt"})


In the above sample function when ever you try to drill down from parent report to child report, you will definitely redirect to specific path only.

 If you deploy the code on to another server.  And when you drill down from parent report to child report then it will automatically navigate to hard code IP Address. So to avoid this we have to specify environment variables available in the pentaho.

So you have to specify drill down function something like below function:

=DRILLDOWN("remote-sugar"; ["env::pentahoBaseURL"]; {"country"; [COUNTRY] | "::pentaho-path"; "/public/TEST/sub-report.prpt"})



Note:  This is a sample function only.
you have to configure web.xml with proper IP Address.


<context-param>
<param-name>fully-qualified-server-url</param-name>
<param-value>http://192.168.10.104:8080/pentaho/</param-value>
</context-param>

When you use drill down functionality with ["env::pentahoBaseURL"] , it will take URL specified in the web.xml