Class StringOneLineHeaderExcelTableToBeanReader<T extends StringExcelTableBean>

All Implemented Interfaces:
IfDataTypeStringExcelTable, IfExcelTable<String>, IfFormatOneLineHeaderExcelTable<String>, IfDataTypeStringExcelTableReader, IfExcelTableReader<String>, IfFormatOneLineHeaderExcelTableReader<String>

public class StringOneLineHeaderExcelTableToBeanReader<T extends StringExcelTableBean> extends StringOneLineHeaderExcelTableReader
Stores the excel table data into a bean.
  • Constructor Details

    • StringOneLineHeaderExcelTableToBeanReader

      public StringOneLineHeaderExcelTableToBeanReader(Class<?> beanClass, @RequireNonnull String sheetName, @RequireNonnull String[] headerLabels, Integer tableStartRowNumber, int tableStartColumnNumber, Integer tableRowSize, T... parameterClass)
      Constructs a new instance. the obtained value from an empty cell is null.

      In most cases null is recommended because Jakarta Validation annotations (like Max) returns valid for null, but invalid for "".

      Parameters:
      beanClass - the class of the generic parameter T is hard to obtain especially the constructor of this class is called directly with setting a class instead of T, like List<Foo> list = new StringOneLineHeaderExcelTableToBeanReader<Foo>(...).
      See here.
    • StringOneLineHeaderExcelTableToBeanReader

      public StringOneLineHeaderExcelTableToBeanReader(Class<?> beanClass, @RequireNonnull String sheetName, @RequireNonnull String[] headerLabels, Integer tableStartRowNumber, int tableStartColumnNumber, Integer tableRowSize, @Nonnull NoDataString noDataString)
      Constructs a new instance with the obtained value from an empty cell.
      Parameters:
      beanClass - the class of the generic parameter T is hard to obtain especially the constructor of this class is called directly with setting a class instead of T, like List<Foo> list = new StringOneLineHeaderExcelTableToBeanReader<Foo>(...).
      See here.
      noDataString - the obtained value from an empty cell. null or "".
  • Method Details

    • readToBean

      public List<T> readToBean(String filePath) throws jp.ecuacion.lib.core.exception.checked.AppException, org.apache.poi.EncryptedDocumentException, IOException
      Obtains excel table in the form of List<PoiStringTableBean> and validate obtained values..
      Parameters:
      filePath - excelPath
      Returns:
      the list of PoiStringTableBean.
      Throws:
      jp.ecuacion.lib.core.exception.checked.AppException - AppException
      org.apache.poi.EncryptedDocumentException - EncryptedDocumentException
      IOException - IOException
    • readToBean

      public List<T> readToBean(String filePath, boolean validates) throws jp.ecuacion.lib.core.exception.checked.AppException, org.apache.poi.EncryptedDocumentException, IOException
      Obtains excel table in the form of List<PoiStringTableBean> and validate obtained values..
      Parameters:
      filePath - excelPath
      validates - whether validation is enabled or not
      Returns:
      the list of PoiStringTableBean.
      Throws:
      jp.ecuacion.lib.core.exception.checked.AppException - AppException
      org.apache.poi.EncryptedDocumentException - EncryptedDocumentException
      IOException - IOException
    • excelTableToBeanList

      protected List<T> excelTableToBeanList(String filePath) throws jp.ecuacion.lib.core.exception.checked.AppException, IOException
      Obtains excel table in the form of List<PoiStringTableBean>.

      Since read method contains validation function, you may want to test the validations. Although you don't want to prepare excel files to test each case.
      When that's the case, you can skip the preparation of excel files by overriding this method and return list you want to test.

      Throws:
      jp.ecuacion.lib.core.exception.checked.AppException
      IOException
    • defaultDateTimeFormat

      public StringOneLineHeaderExcelTableToBeanReader<T> defaultDateTimeFormat(DateTimeFormatter dateTimeFormat)
      Description copied from class: StringExcelTableReader
      Sets defaultDateTimeFormat.
      Overrides:
      defaultDateTimeFormat in class StringOneLineHeaderExcelTableReader
      Parameters:
      dateTimeFormat - dateTimeFormat string for DateTimeFormatter.
      Returns:
      StringExcelTableReader (for method chain)
    • columnDateTimeFormat

      public StringOneLineHeaderExcelTableToBeanReader<T> columnDateTimeFormat(int columnNumber, DateTimeFormatter dateTimeFormat)
      Description copied from class: StringExcelTableReader
      Sets dateTimeFormat for specific column.
      Overrides:
      columnDateTimeFormat in class StringOneLineHeaderExcelTableReader
      Parameters:
      columnNumber - the column number data is obtained from, starting with 1 and column A is equal to columnNumber 1. When the far left column of a table is 2 and you want to speciries the far left column, the columnNumber is 2.
      dateTimeFormat - dateTimeFormat string for DateTimeFormatter.
      Returns:
      StringExcelTableReader (for method chain)
    • ignoresAdditionalColumnsOfHeaderData

      public StringOneLineHeaderExcelTableToBeanReader<T> ignoresAdditionalColumnsOfHeaderData(boolean value)
      Description copied from interface: IfExcelTable
      Stores the boolean value which indicates whether validateHeaderData ignores additional header columns.
      Specified by:
      ignoresAdditionalColumnsOfHeaderData in interface IfExcelTable<T extends StringExcelTableBean>
      Overrides:
      ignoresAdditionalColumnsOfHeaderData in class ExcelTableReader<String>
      Parameters:
      value - boolean