Adding Custom Report Format in Studio

Apart from the default report formats offered by eMACH-Sigma, users can also generate reports in the file format necessary to meet their specific business needs. By creating a custom report engine adaptor, users can accomplish this functionality.

Creating a Custom Report Engine Adaptor

To create a custom report engine adapter, proceed with the following steps:

  1. Create a Java class file implementing the interface IReportEngineAdaptor in the Java class file.
    This interface is a part of the reporting library of eMACH-Sigma applications containing various methods enabling the provision to write their own logic to create the report file with the data.
    Note: The interface IReportEngineAdaptor is available in the CTReportingFW.jar file and the same can be accessed from the CT-eMACH-Sigma team.
    The following methods are available in the IReportEngineAdaptor interface:

    1. Method: ProcessBeforeGenerateReport- This method gives flexibility to process and format the data that is retrieved from a given data source as per needs.

    2. Method: generateReport - Write the logic for this method to create a report file that gets stored on the file system.

      1. Parameter: reportRequest - This object contains configuration information for reports, such as columns and other attributes.

      2. Parameter: dataItems - This object list contains the data that is retrieved from the data builder or data source.
        Note: To read the data from the list, use the code snippet mentioned below.

        List data = dataItems.get() of (List);

The customized report engine adaptor class is expected to return a ReportResponse object which must contain various attributes. Refer to the following code snippet to create a customized Java class file.

The sample code snippet given below is Java Class created for DBF report format and the same way users can write the code logic for their own customized report format.

package com.intellectdesign.export.dbf; import java.io.File; import java.io.FileOutputStream; import java.io.OutputStream; import java.math.BigDecimal; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import java.text.DecimalFormat; import java.util.HashMap; import java.util.List; import java.util.Map; import com.csvreader.CsvWriter; import com.intellectdesign.canvas.constants.preferences.PreferenceConstants; import com.intellectdesign.canvas.export.csv.CsvDelimiters.TextQualifier; import com.intellectdesign.canvas.report.engine.IReportEngineAdaptor; import com.intellectdesign.canvas.report.exception.ReportingException; import com.intellectdesign.canvas.report.util.ReportConstants; import com.intellectdesign.canvas.report.util.ReportUtil; import com.intellectdesign.canvas.report.vo.ReportColumnDefinition; import com.intellectdesign.canvas.report.vo.ReportRequest; import com.intellectdesign.canvas.report.vo.ReportResponse; /** * * @Version 1.0 */ public class DBFExportEngineAdaptor implements IReportEngineAdaptor { /** * @param reportRequest * @param dataItems * @return * @throws ReportingException * @see com.intellectdesign.canvas.report.engine.IReportEngineAdaptor#processBeforeGenerateReport(com.intellectdesign.canvas.report.vo.ReportRequest, * java.util.List) */ @Override public List processBeforeGenerateReport(ReportRequest reportRequest, List dataItems) throws ReportingException { // TODO Auto-generated method stub return null; } /** * @param reportRequest * @param dataItems * @return * @throws ReportingException * @see com.intellectdesign.canvas.report.engine.IReportEngineAdaptor#generateReport(com.intellectdesign.canvas.report.vo.ReportRequest, * java.util.List) */ @Override public ReportResponse generateReport(ReportRequest reportRequest, List dataItems) throws ReportingException { ReportResponse response = new ReportResponse(); File targetFile = new File("D:\\CT\\Temp\\AccountTrasactions.dbf"); try (OutputStream outputWriter = new FileOutputStream(targetFile, false);) { /* * These are the columns selected while creating the report. */ List<ReportColumnDefinition> columns = reportRequest.getReportContext().getReportInstanceDefinition() .getColumns(); /* * The logic starts here to generate the file with the required format. The sample iteration of dataitems is * provided below */ String aValue; List data = (List) dataItems.get(0); Map aRecord; for (int i = 0; i < data.size(); i++) { aRecord = (Map) data.get(i); for (ReportColumnDefinition aColumn : columns) { // TODO: Write your business logic to write the column data into the respective file } } /* * Once the file was written with required data successfully and save on file system, create the below * ReportResponse object with the required attributes */ HashMap responseDataMap = new HashMap(); responseDataMap.put(ReportConstants.REPORT_REF_LOCATION, targetFile.getAbsolutePath()); BigDecimal fileSize = BigDecimal.valueOf(Files.size(Paths.get(targetFile.getAbsolutePath()))); // Convert the file size in bytes into Kilobytes(KB) with 2 decimals DecimalFormat df = new DecimalFormat("0.00"); responseDataMap.put(ReportConstants.REPORT_FILE_SIZE, Double.valueOf(df.format(fileSize.divide(new BigDecimal(1024)).doubleValue()))); responseDataMap.put(ReportConstants.OD_GCIF, reportRequest.getGcif()); responseDataMap.put(ReportConstants.OD_USER_NO, reportRequest.getUserNo()); responseDataMap.put(ReportConstants.FORMAT_ID, reportRequest.getFormatId()); responseDataMap.put(PreferenceConstants.LANGUAGE_ID, reportRequest.getUserPreferenceContext().getLanguageId()); // populating data into the ReportResponse object. response.setReportInstanceId(reportRequest.getReportInstanceId()); response.setReportName(reportRequest.getReportName()); response.setStatus(ReportConstants.STATUS_SUCCESS); response.setReportName(reportRequest.getReportName()); response.setReportInstanceId(reportRequest.getReportInstanceId()); responseDataMap.put(ReportConstants.USER_FILTER_COLUMNS, reportRequest.getUserFilterColumns()); responseDataMap.put(ReportConstants.SQL_BIND_PARAMS, reportRequest.getCustomFilters().get("SqlParams")); responseDataMap.put(ReportConstants.PROCEDURE_PARAMS, reportRequest.getCustomFilters().get("PreHookParams")); responseDataMap.put(ReportConstants.DSPROCEDURE_PARAMS, reportRequest.getCustomFilters().get("ProcedureParams")); responseDataMap.put(ReportConstants.ADD_PARAMS, reportRequest.getCustomFilters().get("AdditionalParams")); response.setResponseObject(responseDataMap); } catch (Exception e) { response.setStatus(ReportConstants.STATUS_FAILURE); response.setErrorCode(ReportConstants.ERR_CD_DEF_ADAPTOR_GEN_REPORT); response.setErrorMsg(ReportUtil.getMessage(ReportConstants.ERR_CD_DEF_ADAPTOR_GEN_REPORT)); throw new ReportingException("ERR_DBF_EXPORT", "Error while generating report in dbf format", e); } return response; } }
  1. Add the Java class file to the following path of the sigma.war file.
    sigma\WEB-INF\lib\CTExportLib.jar\com\intellectdesign\canvas\export\
    The class path of the Java class file should also contain all the third-party jars needed for the contents of the report file.

Adding Customized Report Engine Adaptor to the Report

To add custom report engine adaptor in the report, proceed with the following steps:

  1. Create a report with a required name, id and necessary datasource to fetch data for the report. To create reports refer Configuring a Simple Report.

Note: To display the customized report format (DBF) in the report format list of Studio and eMACH-Sigma, provide the following entries in the report_format _master table in the target schema.

FORMAT_ID

APPLICATION_ID

FORMAT_NAME

REPORT_ENGINE_ADAPTOR_CLASS

FORMAT_ID

APPLICATION_ID

FORMAT_NAME

REPORT_ENGINE_ADAPTOR_CLASS

DBF

CTSTUDIO

DBF

<provide the class path of the custom engine adaptor>

DBF

SIGMA

DBF

<provide the class path of the custom engine adaptor>

  1. Select the added custom format from the Select Allowed Format drop-down field, e.g. DBF.

  1. Select the required columns for the report from the Select Columns to Display drop-down field.

  1. Click on the Additional Info tab.

  1. Add the custom report engine adaptor class path that is included to the sigma.war file in the below highlighted field.

  2. Click Save to save the report.


Generating a Report with Custom Report Format

The configured report with the custom format can be generated in the eMACH-Sigma Application by the following steps:

  1. Log-on to the eMACH-Sigma Application.

  2. Select the configured report in the Application, e.g. Transaction Report.

  1. Select the custom report format (DBF) added in the Report Format field and select other required configurations.

  1. Click Run button to generate the report in the custom format.

The generated custom format report is displayed in the Generated Reports section.

 

Â