...
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.
...
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 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> |
...