integrate with the birt

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

integrate with the birt

guo weizhan
Hi All,

I need some report function for a project, so I try to integrate ofbiz with
the birt, here is some ideas and want to share with you, and if there is any
problems, please let me know.

1. BIRT is the open source project and the license is the Eclipse Public
License that is compatible with Apache;
2. It's a report designer based on Eclipse, and a runtime component that you
can add to your app server. BIRT also offers a charting engine that lets you
add charts to your own application, that's what I need.
3. I want to Ofbiz deal the *.rptdesign as convenient as the jsp;
4.. I want to use the birt servlet to display the rptdesign file as it have
provider full display function, and I can update this code with the birt
easily.

So I create the rpt view handler, this handler doesn't really display the
rpt file but get the display info from the control.xml and pass the
parameters to the birt servlet, and I take the "info" parameter in view-map
as the permission, here is the example:
<handler name="birt" type="view" class="
org.ofbiz.webapp.view.BirtViewHandler" />

<request-map uri="birt">
        <security https="false" auth="false"/>
        <response name="success" type="view" value="testbirt"/>
    </request-map>

<view-map name="testbirt" type="birt" page="/new_report.rptdesign"
info="FACILITY_ADMIN"/>

here is the render code:
 ///////////////////BirtViewHandler //////////////////////////////////////

public class BirtViewHandler implements ViewHandler {

    public static final String module = BirtViewHandler.class.getName();

    protected ServletContext context;

    public void init(ServletContext context) throws ViewHandlerException {
        this.context = context;
     //   context..
    }

    public void render(String name, String page, String info, String
contentType, String encoding, HttpServletRequest request,
HttpServletResponse response) throws ViewHandlerException {
        // some containers call filters on EVERY request, even forwarded
ones,
        // so let it know that it came from the control servlet
       if (request == null) {
              throw new ViewHandlerException("Null HttpServletRequest
object");
          }
          if (page == null || page.length() == 0) {
              throw new ViewHandlerException("Null or empty source");
          }
        String baseURL = request.getScheme( ) + "://"
  + request.getServerName( ) + ":"
  + request.getServerPort( );
        String path=context.getRealPath(page);
        BirtViewHelper.PATH = path;
        BirtViewHelper.PERMISSION = info;
       try{
      response.sendRedirect
(baseURL+"/birt/control/frameset?"+LoginWorker.EXTERNAL_LOGIN_KEY_ATTR+"="+request.getSession().getAttribute(
LoginWorker.EXTERNAL_LOGIN_KEY_ATTR));

     }catch( Exception e){}

    }
}

 ///////////////////END BirtViewHandler
//////////////////////////////////////

 ///////////////////BirtViewHelper//////////////////////////////////////

package org.ofbiz.webapp.view;

public class BirtViewHelper{
 public static String PATH = new String();
 public static String PERMISSION = new String();
}

///////////////////END BirtViewHelper//////////////////////////////////////

here is the permission check in birt servlet :



///////////////////AuthenticateHelper //////////////////////////////////////

package org.eclipse.birt.report.servlet;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletContext;

import org.ofbiz.security.Security;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.webapp.control.LoginWorker;
import org.ofbiz.webapp.view.BirtViewHelper;

public class AuthenticateHelper {
 public static boolean hasPemission(HttpServletRequest request,
   HttpServletResponse response, ServletContext context)
 {
  LoginWorker.checkExternalLoginKey(request, response) ;
  GenericValue userLogin =
(GenericValue)request.getSession().getAttribute("userLogin");
  Security security = (Security)request.getAttribute("security");
  if (security == null) {
            security = (Security) context.getAttribute("security");
        }

  return security.hasPermission(BirtViewHelper.PERMISSION, userLogin);
 }
}

///////////////////END AuthenticateHelper
//////////////////////////////////////



you can download the BIRT code http://www.open-agile.com/birt.rar, place
those code in the framework folder add add this module to the
ofbiz-component.xml, and add the BirtViewHandler.java ,BirtViewHelper.java in
the ofbiz\framework\webapp\src\org\ofbiz\webapp\view.

Birt has a bug when export as word document,  it will be fixed later.
Reply | Threaded
Open this post in threaded view
|

Re: integrate with the birt

Amine AZZI
I have experiencing BIRT last days, it has a nice feature when it concerns
creating a data source needing a script. in the script, we can call the
GenericDelegator and do queries using Ofbiz entity engine.

Your code for integration is great as I used the BIRT war directly without
passing through a rendrer.

thank you  for the help.

Amine.

2007/7/21, guo weizhan <[hidden email]>:

>
> Hi All,
>
> I need some report function for a project, so I try to integrate ofbiz
> with
> the birt, here is some ideas and want to share with you, and if there is
> any
> problems, please let me know.
>
> 1. BIRT is the open source project and the license is the Eclipse Public
> License that is compatible with Apache;
> 2. It's a report designer based on Eclipse, and a runtime component that
> you
> can add to your app server. BIRT also offers a charting engine that lets
> you
> add charts to your own application, that's what I need.
> 3. I want to Ofbiz deal the *.rptdesign as convenient as the jsp;
> 4.. I want to use the birt servlet to display the rptdesign file as it
> have
> provider full display function, and I can update this code with the birt
> easily.
>
> So I create the rpt view handler, this handler doesn't really display the
> rpt file but get the display info from the control.xml and pass the
> parameters to the birt servlet, and I take the "info" parameter in
> view-map
> as the permission, here is the example:
> <handler name="birt" type="view" class="
> org.ofbiz.webapp.view.BirtViewHandler" />
>
> <request-map uri="birt">
>         <security https="false" auth="false"/>
>         <response name="success" type="view" value="testbirt"/>
>     </request-map>
>
> <view-map name="testbirt" type="birt" page="/new_report.rptdesign"
> info="FACILITY_ADMIN"/>
>
> here is the render code:
> ///////////////////BirtViewHandler //////////////////////////////////////
>
> public class BirtViewHandler implements ViewHandler {
>
>     public static final String module = BirtViewHandler.class.getName();
>
>     protected ServletContext context;
>
>     public void init(ServletContext context) throws ViewHandlerException {
>         this.context = context;
>      //   context..
>     }
>
>     public void render(String name, String page, String info, String
> contentType, String encoding, HttpServletRequest request,
> HttpServletResponse response) throws ViewHandlerException {
>         // some containers call filters on EVERY request, even forwarded
> ones,
>         // so let it know that it came from the control servlet
>        if (request == null) {
>               throw new ViewHandlerException("Null HttpServletRequest
> object");
>           }
>           if (page == null || page.length() == 0) {
>               throw new ViewHandlerException("Null or empty source");
>           }
>         String baseURL = request.getScheme( ) + "://"
>   + request.getServerName( ) + ":"
>   + request.getServerPort( );
>         String path=context.getRealPath(page);
>         BirtViewHelper.PATH = path;
>         BirtViewHelper.PERMISSION = info;
>        try{
>       response.sendRedirect
>
> (baseURL+"/birt/control/frameset?"+LoginWorker.EXTERNAL_LOGIN_KEY_ATTR+"="+request.getSession().getAttribute(
> LoginWorker.EXTERNAL_LOGIN_KEY_ATTR));
>
>      }catch( Exception e){}
>
>     }
> }
>
> ///////////////////END BirtViewHandler
> //////////////////////////////////////
>
> ///////////////////BirtViewHelper//////////////////////////////////////
>
> package org.ofbiz.webapp.view;
>
> public class BirtViewHelper{
> public static String PATH = new String();
> public static String PERMISSION = new String();
> }
>
> ///////////////////END
> BirtViewHelper//////////////////////////////////////
>
> here is the permission check in birt servlet :
>
>
>
> ///////////////////AuthenticateHelper
> //////////////////////////////////////
>
> package org.eclipse.birt.report.servlet;
>
> import javax.servlet.http.HttpServletRequest;
> import javax.servlet.http.HttpServletResponse;
> import javax.servlet.ServletContext;
>
> import org.ofbiz.security.Security;
> import org.ofbiz.entity.GenericValue;
> import org.ofbiz.webapp.control.LoginWorker;
> import org.ofbiz.webapp.view.BirtViewHelper;
>
> public class AuthenticateHelper {
> public static boolean hasPemission(HttpServletRequest request,
>    HttpServletResponse response, ServletContext context)
> {
>   LoginWorker.checkExternalLoginKey(request, response) ;
>   GenericValue userLogin =
> (GenericValue)request.getSession().getAttribute("userLogin");
>   Security security = (Security)request.getAttribute("security");
>   if (security == null) {
>             security = (Security) context.getAttribute("security");
>         }
>
>   return security.hasPermission(BirtViewHelper.PERMISSION, userLogin);
> }
> }
>
> ///////////////////END AuthenticateHelper
> //////////////////////////////////////
>
>
>
> you can download the BIRT code http://www.open-agile.com/birt.rar, place
> those code in the framework folder add add this module to the
> ofbiz-component.xml, and add the BirtViewHandler.java ,BirtViewHelper.javain
> the ofbiz\framework\webapp\src\org\ofbiz\webapp\view.
>
> Birt has a bug when export as word document,  it will be fixed later.
>