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.
...
Create a Java class file implementing the interface IReportEngineAdaptor in the Java class file.
This interface is a part of the reporting library of sigma 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:Method: ProcessBeforeGenerateReport- This method gives flexibility to process and format the data that is retrieved from a given data source as per needs.
Method: generateReport - Write the logic for this method to create a report file that gets stored on the file system.
Parameter: reportRequest - This object contains configuration information for reports, such as columns and other attributes.
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.Code Block List data = dataItems.get() of (List);
...
Code Block | ||
---|---|---|
| ||
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; } } } |
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.
...
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 |
---|---|---|---|
DBF | CTSTUDIO | DBF | <provide the class path of the custom engine adaptor> |
DBF | SIGMA | DBF | <provide the class path of the custom engine adaptor> |
...
The configured report with the custom format can be generated in the eMACH-Sigma Application by the following steps:
Log-on to the eMACH-Sigma Application.
Select the configured report in the Application, e.g. Transaction Report.
...