moqui

Is there a recommended way to skip first line of a CSV file in Moqui?


I have a CSV file generated by another programme that is uploaded to Moqui as a FileItem without any editing done on the CSV file.

So it has a header that I don't want to use, therefore I manually specify csvEntityName and csvFieldNames for the entity data loader. But the header is taken as the first record. - Is there a recommended way to skip the first line?


Solution

  • Digging deeper, in EntityDataLoaderImpl.groovy we have:

    CSVParser parser = CSVFormat.newFormat(edli.csvDelimiter)
                    .withCommentMarker(edli.csvCommentStart)
                    .withQuote(edli.csvQuoteChar)
                    .withSkipHeaderRecord(true) // TODO: remove this? does it even do anything?
                    .withIgnoreEmptyLines(true)
                    .withIgnoreSurroundingSpaces(true)
                    .parse(reader)
    

    The reason .withSkipHeaderRecord(true) currently does nothing is you first have to specify that the file has a header to skip using .withHeader(). ( https://commons.apache.org/proper/commons-csv/apidocs/org/apache/commons/csv/CSVFormat.html#withFirstRecordAsHeader--)

    If you add that, the .withSkipHeaderRecord(boolean) will skip the header record if passed 'true'.

    (I think this needs to be made an issue, so I will do that.)