Class CsvToQRecordAdapter

java.lang.Object
com.kingsrook.qqq.backend.core.adapters.CsvToQRecordAdapter

public class CsvToQRecordAdapter extends Object
Adapter class to convert a CSV string into a list of QRecords. Based on which method is called, can either take a pipe, and stream records into it - or return a list of all records from the file. Either way, at this time, the full CSV string is read invalid input: '&' parsed - a future optimization might read the CSV content from a stream as well.
  • Constructor Details

    • CsvToQRecordAdapter

      public CsvToQRecordAdapter()
  • Method Details

    • buildRecordsFromCsv

      public void buildRecordsFromCsv(RecordPipe recordPipe, String csv, QTableMetaData table, AbstractQFieldMapping<?> mapping, Consumer<QRecord> recordCustomizer) throws QException
      stream records from a CSV String into a RecordPipe, for a given table, optionally using a given mapping.
      Throws:
      QException
    • buildRecordsFromCsv

      public List<QRecord> buildRecordsFromCsv(String csv, QTableMetaData table, AbstractQFieldMapping<?> mapping) throws QException
      convert a CSV String into a List of QRecords, for a given table, optionally using a given mapping.
      Throws:
      QException
    • buildRecordsFromCsv

      public void buildRecordsFromCsv(CsvToQRecordAdapter.InputWrapper inputWrapper) throws QException
      convert a CSV String into a List of QRecords, for a given table, optionally using a given mapping. todo - meta-data validation, type handling
      Throws:
      QException
    • makeHeadersUnique

      protected List<String> makeHeadersUnique(List<String> headers)
      For a list of headers, if any duplicates are found, add a numeric suffix to the duplicates. So this header row: A,B,C,C,C Would become: A,B,C,C 2,C 3 See unit test for more scenarios - some of which we do not handle well yet, such as "C 2, C, C 3"
    • getRecordList

      public List<QRecord> getRecordList()
      Getter for recordList - note - only is valid if you don't supply a pipe in the input. If you do supply a pipe, then you get an exception if you call here!