The ERSClient is a Java class that provides the core API for all reporting-related functions. It is used with Java applications like servlets, JSP or even a simple standalone Java client. The ERSClientCommand is a wrapper class of ERSClient, this provides script based integration for command line invocation of reports.
The supporting Java libraries are placed in the RepertoireServer\clients\lib directory. RepertoireClient.jar is the core library containing the API. The other support libraries are log4j for logging mechanism and Glint.jar for ui components.
Elixir Repertoire Server Client provides a light weight interface to connect to the Repertoire Server. The basic features are listing file system, querying reports deployed in the report server repository, querying dynamics parameters in the report and generating report.
The full list of the APIs for RepertoireClient is found in RepertoireServer\web-resources\help\api The basic steps to make use of the functions are as follows:
Determine the Report server IP or host name, Port number, user name and password.
Create a new instance of com.elixirtech.ers2.client.ERSClient class. If the server has been configured in secure mode, setSecure(true) must be called on the ERSClient instance. Failure to set this to match the server mode will result in encryption/decryption errors.
Select the API to use to generate report, list filesystem etc. These basic functions are:
// retrieve the list of file systems in the repository. String[] getFileSystems(); // retrieve a file system from the repository. IFileSystem getFileSystem(String filesystemName); // retrieve the list of the reports in a filesystem. String[] getReports(String filesystemName); // retrieve the list of the parameters in a report. Parameter[] getParameters(String report); // generate a report into an output stream. IJobInfo renderReport(String report, String mimeType, OutputStream os, Properties properties);
Below are some code examples to interface with the report server from a java client.
Example 7.1. Listing the file systems in a server repository.
File systems are used for storage. They could be file directories or jar files the implementation is transparent to the user. The getFileSystems API will list the file systems.
import com.elixirtech.report2.runtime.IFileSystem; public void listReports( ) { String[] filesystem = client.getFileSystems(); }
Example 7.2. Listing the reports deployed in a file system.
Once you have obtained the file system name (String), you can list the report names in that file system.
public void listReports( ) { ERSClient client = new ERSClient(localhost, 8080, username, MyPassword); String[] reports = client.getReports("myfilesystemname"); }
Example 7.3. Generating a report
This illustrates report
generation where "outputstream" is the java io stream that
the report output will be written to. Job Information can be retrieve
via the interface IJobInfo
.
import java.io.OutputStream; import com.elixirtech.ers2.client.ERSClient; import com.elixirtech.report2.runtime.IJobInfo; ... public void generateReport( OutputStream outputstream) { ERSClient client = new ERSClient(localhost,8080, username, MyPassword); IJobInfo job = client.renderReport( "/myrepository/myreport.rml", "application/pdf", outputstream, properties); }
Example 7.4. Request for Data listing.
This illustrates how you can query for the data source for a list of records. The output will be written on the stream. Depending on the mime type, the format of returning dataset may in the format of excel (application/vnd.ms-excel), comma separated file (text/csv) or default data source xml format (text/xml).
public void generateDataSource() { String dsFS = "/ElixirSamples/DataSource/ChartData.ds"; File f = new File("ChartData.ds"); if (f.exists()) f.delete(); FileOutputStream fos = null; try { fos = new FileOutputStream(f); Properties properties = new Properties(); //mime-type format needed to return the data properties.put("mime-type", "text/xml"); m_ERSClient.generateData(dsFS, fos,properties); if (fos != null) try { fos.close(); } catch (IOException e) { } } catch (Exception ex) { System.err.println("Error: " + ex.toString()); } }
Example 7.5. Trigger for Data Store process.
Data Store allows the user to trigger a section of actions to process data and finally load the final dataset to specific location i.e. Database table, file etc. The API ,generateData, is used but add parameter key "datastore" and the datastore name is needed to identify which data store to activate.
public void generate_DataStore() { String dstoreFS="/ElixirSamples/DataSource/CompositeEmployee.ds"; try { Properties properties = new Properties(); //datastore property requirement to identify which // data store to push the data to. properties.put("datastore", "CSV"); m_ERSClient.generateData(dstoreFS, outputstream, properties); } catch (Exception ex) { // ... } }
Example 7.6. Using IJobInfo interface to extract job information.
When rendering reports or generating data, the methods return an IJobInfo interface. You can use this interface to extract information about a particular job. An example is as listed below:
import com.elixirtech.report2.runtime.IJobInfo; ... private static double diffSecs(double start, double end) { return (end-start)/1000d; } public void displayReportGenerateJobInfo(IJobInfo myJob) { SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd-Hmm"); m_DateFormat = df.format(new Date()); long timeReceived = job.getLong(IJobInfo.JOB_RECEIVED); long timeStarted = job.getLong(IJobInfo.JOB_STARTED); long timeEnded = job.getLong(IJobInfo.JOB_ENDED); double totalQueueTime = diffSecs(timeReceived,timeStarted); double totalJobProcessTime = diffSecs(timeStarted,timeEnded); double totalJobTime = diffSecs(timeReceived,timeEnded); int pageCount = job.getInteger(IJobInfo.PAGE_COUNT); int recordCount = job.getInteger(IJobInfo.RECORD_COUNT); String mimeType = job.getString(IJobInfo.MIME_TYPE); long sizeBytes = job.getLong(IJobInfo.BYTE_SIZE); // display or log these values as you choose }
Example 7.7. Configuring custom status code and exception message
In this example, the user will receive a custom message, which will display in third-party API software.
public void rendersReport(String reportName, Properties prop) { ERSClient ersClient = new ERSClient(localhost, 8080, username, MyPassword); try { FileOutputStream fos = new FileOutputStream( new File("sample.pdf")); IJobInfo ji = ersClient.renderReport(reportName, "application/pdf", fos, prop); System.out.println( "Job Received: " ...... + ji.getString(IJobInfo.NAME) + ", " + "Status Code: " + ji.getString(IJobInfo.STATUS_CODE) + ", " + "Exception Message: " + ji.getString(IJobInfo.JOB_EXCEPTION) ); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (NetException e) { e.printStackTrace(); } finally { ersClient.close(); } } public static void main(String[] args) { System.out.println(">>>1 Generate Report using File Output Stream"); testClient.rendersReport("/Path/sample.rml",params) }