7.4. ERES Menu API Overview

7.4.1. Introduction and Setup

A Menu is typically a jsp page that shows all the published reports and charts. Depending on the options available, a menu may allow the user to choose the format in which the report and/or chart are to be presented. The menus discussed here are analogous to those described in the Menu chapter.

ERES provides an easy-to-use application programming interface (API) that allows users to create and customize menus to show in their servlet/jsp applications. This API is written in 100% Pure Java and can be run on any platform with no or few minimal changes. Any and every part of the menu is customizable using the API.

The main package for ERES Menu API is the quadbase.reportorganizer.MenuAPI package. Associated with this package are five main classes: MenuNode, MenuTableRow, QbMenu, ScheduleJob and Util. The remainder of this chapter will give you an overview of these various classes and their usage. Please note that the complete documentation is located at help/ERESapidocs/index.html.

The jar files for using ERES Menu API are located in the ERES/lib directory. These jar files should already be present in your application's CLASSPATH when you set up ERES.

Currently, you can only use ERES Menu API in a servlet/jsp environment. The servlets/jsps must also run in the same servlet context as ERES server.

7.4.2. Using the API

This section discusses the usage of ERES Menu API with code examples and contains descriptions of main API classes.

7.4.2.1. Creating and Customizing an ERES Menu

The sections below describe the various steps involved in creating and customizing an ERES Menu:

7.4.2.1.1. Connecting to ERES Server

The first step is to connect to ERES server. After successfully connected to the server, a QbMenu object can be allocated. QbMenu is the main class containing contents for a Menu page.

The ERES server is simply an object that resides in the ServletContext of the web application. Since you will want to put most Java code in your Java bean, you will need to pass the HttpServletRequest and ServletContext objects from the jsp to the bean. The following jsp and bean code illustrates this:

  • Example jsp (Menu_login.jsp):

<!-- import the bean class -->
<%@page language="java" import="help.examples.Menu.exampleMenuLogin"%>

<!-- include/instantiate the bean -->
<jsp:useBean id="exampleMenuLogin" scope="session" class="help.examples.Menu.exampleMenuLogin" />

<!-- pass the HttpServletRequest and ServletContext objects to the bean -->
<% exampleMenuLogin.processRequest(request, application); %>
          

where the jsp passes the request (HttpServletRequest) and application (ServletContext) to the Java bean MenuLogin's processRequest method. Next, you will need to implement code in the bean that allocates the QbMenu object from the ServletContext:

  • Example bean (MenuLogin.java):

      public void processRequest(HttpServletRequest request, ServletContext context) throws IOException {

            QbMenu qbMenu = new QbMenu(context.getAttribute(QbMenu.QBMENUDATA));

      }
          

where context.getAttribute(QbMenu.QBMENUDATA) is set when ERES server started.

7.4.2.1.2. Getting User Menu Page

The second step uses the QbMenu object to authenticate the user. This is easy since all security and permission checks are performed by ERES server. If login is successful, you can store the QbMenu object for the session so that for the duration of the session, the user will not have to login again. The following code illustrates this:

boolean loginSuccess = qbMenu.login(userName, password);
if (loginSuccess) {

      //store the QbMenu object in session

      session.setAttribute("QBMENUOBJ", qbMenu);

}
          

where "QBMENUOBJ" is the name that you can use later for retrieving the stored QbMenu. This means that after storing the QbMenu in the session, in other jsp pages by doing session.getAttribute("QBMENUOBJ"). The QbMenu.login method returns true only if the user name and password match. If login failed, the user can be prompted again.

[Note]Note

Login MUST succeed for the QbMenu object to return a valid Menu.

7.4.2.1.3. Getting all Visible Nodes

After authenticating the user, you can get a list of authorized Menu nodes, which contain reports or charts, from the QbMenu. A node is either a project or a folder in ERES Organizer.

MenuNode[] MenuNode = qbMenu.getMenuNodeList(null);
          

Passing in null to the getMenuNodeList method results in getting all the available Menu nodes. If you pass in a string, the method will return only those nodes items that contain the string.

[Note]Note

The path for the Menu node will be a complete one, i.e. Project1/Folder1/SubFolder2

7.4.2.1.4. Getting the Node Details

Once you have retrieved the Menu nodes, the next step is get the node details, namely, the files contained in the node. Conceptually, each item in the node is a row and is represented by the MenuTableRow object. The following code iterates through each file in all nodes:

for (int i = 0; i < MenuNode.length; i++) {

      for (int j = 0; j < MenuNode[i].getRowItemCount(); j++) {
            MenuTableRow MenuTableRow = MenuNode[i].getMenuTableRowAt(j);

      }

}
          
7.4.2.1.5. Getting the File Details

You can obtain all the information of the file (such as file name, description, whether it is a chart or report etc) using the MenuTableRow class.

The following methods are used to obtain the file details:

String getDescription()
Returns the description for the row item

String getName()
Returns the name for the row item

String getPath()
Returns the path for the row item

ScheduleJob getScheduleJob()
Returns the schedule job information for the row item

ScheduleJob getArchiveJob()
Returns the archive job information for the row item

String getSecurityLevel()
Returns the security level for the row item

String getURL()
Returns the URL for the row item

boolean isArchiveOptionAvail()
Returns whether the archive option is available for the row item

boolean isScheduleOptionAvail()
Returns whether the schedule option is available for the row item

boolean isChart()
Returns whether the row item is a chart

boolean isReport()
Returns whether the row item is a report

boolean isDashboard()
Returns whether the row item is a dashboard
          

Using the above methods, you can get the various file details.

7.4.2.1.6. Scheduling/Archiving

After getting the file details (see previous section), you can also get all the details for any scheduled or archived jobs for the particular file. This can be done by getting the ScheduleJob object from MenuTableRow.

The following methods are used to obtain any scheduling/archiving information:

long getEndDate()
Returns the ending date for the row item's schedule job.  If no end date is specified, -1 is returned

long getStartDate()
Returns the starting date for the row item's schedule job

String getName()
Returns the name of the job for the row item

long getNextExportTime()
Returns the next scheduled export time for the row item

int getParamSetCount()
Returns the number of parameter sets for the row item's schedule/archive job

Object[] getParamSet(int setNumber)
Returns the selected parameter value(s) for the specified parameter set for the row item's schedule/archive job

String[] getParamNames()
Returns the names of all the parameters for the row item

String getReportLocation()
Returns the location of the report (if the row item happens to be a report)

String getChartLocation()
Returns the location of the chart (if the row item happens to be a chart)

String getScheduledFileLocation()
Returns the location of the exported file created by the row item's schedule

String getScheduledFileLocation(int paramIndex)
Returns the location of the exported file, for the specified parameter set, created by the row item's schedule

String getSecurityLevel()
Returns the security level for the row item's schedule

boolean isChart()
Returns whether the row item's job is for a chart

boolean isReadable()
Returns whether the user has permission to the row item's job

boolean isReport()
Returns whether the row item's job is for a report

boolean isArchiveJob()
Returns whether the row item's job is an archived job

boolean isScheduleJob()
Returns whether the row item's job is a scheduled job

int getArchiveFilesCount()
Returns the total number of archived files for the row item

long getArchiveDate(int index)
Returns the date of the specified archived file for the row item

String getArchiveFileLocation(int index)
Returns the location of the specified archive file for the row item

String getArchiveFileLocation(int index, int paramIndex)
Returns the location of the specified archive file, using the specified parameter set, for the row item
          

You can get the various details for any scheduled/archived jobs for the particular row item by using the above methods.

7.4.2.2. Exporting Reports/Charts using the LookupServlet Servlet

Depending on your needs and architecture, you can setup the Menu to show the reports and charts in various static formats (such as DHTML, PDF, JPEG, GIF, PNG, etc) or in an interactive applet. You can code your own servlet using the APIs provided in the ERES Reporting API Overview and ERES Charting API Overview chapters to get the templates and export them to the format desired.

ERES also comes with a ready-made servlet that can take different parameters to produce the report and/or chart in the format desired without you having to write any additional servlet code. This servlet is the LookupServlet servlet and is generally in the ERES/servlet context (for example, http://192.168.0.1:8080/ERES/servlet/LookupServlet). For more details on this servlet and the various parameters it requires, please refer to the Designer guide.

7.4.3. Javadoc

Javadoc for the entire API is provided along with ERES. It is located here (Reports and charts) and here (ES functions).

7.4.4. Summary

ERES already provides a menu for any user-created reports and/or charts. This menu can be reached by logging into the Organizer and choosing Published Files. In addition to this, ERES also provides an easy-to-use, yet powerful library to create your own menu in your own styles to display any reports and/or charts.

The jsp code discussed in this chapter is also available in the ERES/help/examples/Menu directory (this directory contains both the jsp pages and the css styles). The ERES/WEB-INF/classes/help/examples/Menu directory contains the source and class files for the beans. This example demonstrates the steps given above.

Please note that the Menu API requires a JDK 1.5 or above. The ERES Menu API and jsp pages have been tested with Mozilla (1.3 and above), Firefox (0.91 and above), and Microsoft Internet Explorer (5.x and above) on the Windows NT/2000, Solaris, Linux, AIX, and HP platforms.