Crystal Enterprise Report Source


So far, examples have used just the Java Reporting Component to access stand-alone Crystal Report .RPT files. However, web-based JSP environments may also need to access Business Objects in other web reporting environments, such as Crystal Enterprise Professional or Premium Edition. In particular, you may wish to access reports from the CE Professional or Premium Crystal Management Server via a JSP application.

Note  

More information on Crystal Enterprise Professional and Premium Editions is available in Chapters 24, 25, and 26.

First, you need to retrieve the Crystal Enterprise EnterpriseSession object. This connects your JSP application to an existing Crystal Enterprise system, as well as authenticating your Crystal Enterprise security through the Enterprise Crystal Management Server (CMS).

 String user = "Administrator"; 
String password = "";
String cmsName = "CMS-NAME";
String cmsAuthType = "secEnterprise";

//declare the Enterprise Session object
//Logon to the CMS and retrieve an Enterprise Session
IEnterpriseSession es = CrystalEnterprise.getSessionMgr().logon( user, password, cmsName, cmsAuthType);

Once you have the connection, you must create and send a SQL query to request the information you need from the Crystal Enterprise CMS. The data returned is then stored in a collection. You then select data from the collection as needed by your JSP application.

You ll need to create an instance of the IInfoStore. The IInfoStore class is used to store a reference to the service provided by the Crystal Enterprise CMS, which is received by calling the getService() method that is defined in the EnterpriseSession class. This is shown here:

 IInfoStore iStore=null; 

You also need to declare references to the IInfoObjects class and the IInfoObject class. The IInfoObjects class is the collection that references data returned by the Crystal Enterprise CMS. The IInfoObject class references items that are contained in the collection. Here s how this is done:

 IInfoObjects oInfoObjects=null; 
IInfoObject oInfoObject=null;

After creating these references, it is time to retrieve the service from the Crystal Enterprise CMS. You ll need this in order to send the SQL query to the CMS. The service is returned by calling the getService() method that is defined in the EnterpriseSession class. In our example, es is the name of the instance of the EnterpriseSession class. Here s how to call this method:

 iStore = (IInfoStore) es.getService("", "InfoStore"); 

In order to retrieve data from the CMS, you ll need to create a SQL query and send the query to the server. Examples of SQL syntax required to properly query the CE CMS can be found in Crystal Enterprise Developer documentation. The SQL query must be in the form of a string that is passed to the query() method that is defined in the IInfoStore class. The query() method returns an IInfoObjects containing a response to your query. This is illustrated here:

 oInfoObjects = (IInfoObjects) iStore.query("Select * from CI_INFOOBJECTS 
Where SI_NAME='Consolidated Balance Sheet'");

Once the data is retrieved, you can call the get() method defined in the IInfoObjects class to select items from the collection. The get() method requires one argument, which is an integer representing the row of data within the collection that you want to access. The get() method returns reference to that data, as shown here:

 oInfoObject = (IInfoObject)oInfoObjects.get(0); 

Next, you ll need an IReportsourceFactory that you can obtain by calling the getService() method, passing it the PSReportFactory request as the second argument, as illustrated here:

 IReportSourceFactory rptFactory = es.getService("","PSReportFactory"); 

The IReportsourceFactory is used to call the openReportSource() method that returns the report source. Once you retrieve the report source, you can access elements of the report using classes that have been illustrated throughout this chapter. You can then set the report source as the attribute for the session by calling the setAttribute() method, which is shown here:

 IReportSource reportSource = rptFactory.openReportSource 
(oInfoObject,request.getLocale());
session.setAttribute("rptSource", reportSource);

Here is the completed JSP application that shows how to retrieve a report from Crystal Enterprise Professional or Premium Edition:

 <%@ page import="com.crystaldecisions.sdk.occa.infostore.IInfoObjects, 
com.crystaldecisions.sdk.occa.infostore.IInfoObject,
com.crystaldecisions.sdk.occa.infostore.IInfoStore,
com.crystaldecisions.sdk.occa.managedreports.IReportAppFactory,
com.crystaldecisions.sdk.occa.report.reportsource.IReportSource,
com.crystaldecisions.sdk.occa.managedreports.IReportSourceFactory,
com.crystaldecisions.sdk.framework.CrystalEnterprise,
com.crystaldecisions.sdk.framework.IEnterpriseSession"%>
<%
String user = "Administrator";
String password = "";
String cmsName = "CMS-NAME";
String cmsAuthType = "secEnterprise";
IEnterpriseSession es = CrystalEnterprise.getSessionMgr().logon( user,
password, cmsName, cmsAuthType);
IInfoStore iStore=null;
IInfoObjects oInfoObjects=null;
IInfoObject oInfoObject=null;
iStore = (IInfoStore) es.getService("", "InfoStore");

oInfoObjects = (IInfoObjects) iStore.query("Select * from CI_INFOOBJECTS Where
SI_NAME='Consolidated Balance Sheet'");
oInfoObject = (IInfoObject)oInfoObjects.get(0);

IReportSourceFactory rptFactory = es.getService("","PSReportFactory");
IReportSource reportSource =
rptFactory.openReportSource(oInfoObject,request.getLocale());
session.setAttribute("rptSource", reportSource);
%>
Note  

The preceding section of code requires that a properly operating Crystal Enterprise Professional or Premium Edition system be running on your network. Detailed information on these versions of Crystal Enterprise can be found in Chapters 24, 25, and 26.




Crystal Reports 10
Crystal Reports 10: The Complete Reference
ISBN: B005DI80VA
EAN: N/A
Year: 2004
Pages: 223
Authors: George Peck

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net