Class DataExporter

java.lang.Object
com.jbstrap.core.data.DataExporter
Direct Known Subclasses:
CSVExport, ExcelExport

public abstract class DataExporter extends Object
The data exporting parent class, that requires the implementation of the start, process end methods. It also provides the methods, that can (or must be) used when exporting data.
Since:
4.0
Author:
JBStrap
  • Field Details

    • params

      protected Parameters params
    • columnMap

      protected final Map<String,String> columnMap
      The map containing the columns and their headers.
      The Map key is the column name, and the value is the header.
  • Constructor Details

    • DataExporter

      public DataExporter(Parameters params)
      Creates a DataExporter instance with the specified export settings (parameters).
      Parameters:
      params - Export parameters
  • Method Details

    • addColumnMapping

      public DataExporter addColumnMapping(String columnName)
    • addColumnMapping

      public DataExporter addColumnMapping(String columnName, String title)
      Adds a column mapping to the exporter
      Parameters:
      columnName - The column name
      title - The column header text
      Returns:
      The data exporter class
    • removeColumnMapping

      public DataExporter removeColumnMapping(String columnName)
      Removes a column mapping from the exporter
      Parameters:
      columnName - The name of the column that has the mapping to be removed
      Returns:
      The data exporter class
    • getColumnMapping

      public Map<String,String> getColumnMapping()
      Gets a map of the Column Mapping assigned.
      Returns:
      The column mappings in a map format. The map key is the column name, the value is the header text
    • start

      public abstract boolean start()
      This method is to be called upon starting the export process. Necessary objects and the export file are initialized at this point.
      Returns:
      Initialization success
    • process

      public abstract boolean process(List<Record> data)
      Processing records retrieved using lazy fetch and writing them into the export file. This method is called every time the query is performed and the retrieved set of records is not empty.
      Parameters:
      data - Records retrieved using lazy fetch
      Returns:
      If an exception is thrown and more records cannot be written into the export file, then false, otherwise true. If true, the export process continues, otherwise the end method is called.
    • end

      public abstract byte[] end() throws IOException
      This method is to be called after completing the export process. The method closes all the sources opened in the start method.
      Returns:
      The exported file returned as a byte array
      Throws:
      IOException - An exception is thrown while handling a source
    • getExtension

      public String getExtension()
      Gets the export file extension. If no extension is specified, then the export file is created using the export.defaultExtension message source, which is an empty string by default
      Returns:
      Export file extension