Class CharacterSeparatedImportMetadataSourceServiceImpl

All Implemented Interfaces:
MetadataFieldMapping<PlainMetadataSourceDto,MetadataContributor<PlainMetadataSourceDto>>, FileSource, MetadataSource

public class CharacterSeparatedImportMetadataSourceServiceImpl extends AbstractPlainMetadataSource
This class is an implementation of MetadataSource which extends AbstractPlainMetadataSource in order to parse "character separated" files like csv, tsv, etc using the Live Import framework.
Author:
Pasquale Cavallo
  • Constructor Details

    • CharacterSeparatedImportMetadataSourceServiceImpl

      public CharacterSeparatedImportMetadataSourceServiceImpl()
  • Method Details

    • setSkipLines

      public void setSkipLines(Integer skipLines)
      Set the number of lines to skip at the start of the file. This method is suitable, for example, to skip file headers.
      Parameters:
      skipLines - number of the line at the start of the file to skip.
    • getSkipLines

      public Integer getSkipLines()
      Returns:
      the number of the lines to skip
    • setSeparator

      public void setSeparator(char separator)
      Method to inject the separator This must be the ASCII integer related to the char. In example, 9 for tab, 44 for comma
    • setQuoteCharacter

      public void setQuoteCharacter(char quoteCharacter)
      Method to inject the escape character, usually ". This must be the ASCII integer related to the char. In example, 9 for tab, 44 for comma
    • setEscapeCharacter

      public void setEscapeCharacter(char escapeCharacter)
      Method to inject the escape character, usually \. This must be the ASCII integer related to the char. In example, 9 for tab, 44 for comma
    • getImportSource

      public String getImportSource()
      Description copied from interface: MetadataSource
      The string that identifies this import implementation. Preferable a URI
      Returns:
      the identifying uri
    • setImportSource

      public void setImportSource(String importSource)
      Method to set the name of the source
    • readData

      protected List<PlainMetadataSourceDto> readData(InputStream inputStream) throws FileSourceException
      The method process any kind of "character separated" files, like CSV, TSV, and so on. It return a List of PlainMetadataSourceDto. Using the superclass methods AbstractPlainMetadataSource.getRecord(s), any of this element will then be converted in an ImportRecord. Columns will be identified by their position, zero based notation. Separator character and escape character MUST be defined at class level. Number of lines to skip (headers) could also be defined in the field skipLines.
      Specified by:
      readData in class AbstractPlainMetadataSource
      Parameters:
      InputStream - The inputStream of the file
      Returns:
      A list of PlainMetadataSourceDto
      Throws:
      FileSourceException - if, for any reason, the file is not parsable
    • setMetadataFieldMap

      public void setMetadataFieldMap(Map<MetadataFieldConfig,MetadataContributor<PlainMetadataSourceDto>> metadataFieldMap)
      Description copied from class: AbstractMetadataFieldMapping
      Defines which metadatum is mapped on which metadatum. Note that while the key must be unique it only matters here for postprocessing of the value. The mapped MetadatumContributor has full control over what metadatafield is generated.
      Overrides:
      setMetadataFieldMap in class AbstractMetadataFieldMapping<PlainMetadataSourceDto>
      Parameters:
      metadataFieldMap - The map containing the link between retrieve metadata and metadata that will be set to the item.