java.lang.Object
de.hybris.platform.acceleratorservices.dataimport.batch.task.ImpexTransformerTask
All Implemented Interfaces:
HeaderTask, org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware
Direct Known Subclasses:
MarketplaceImpexTransformerTask

public class ImpexTransformerTask extends Object implements HeaderTask, org.springframework.context.ApplicationContextAware
Transformer that retrieves a CSV file and transforms it to an impex file.
  • Constructor Details

    • ImpexTransformerTask

      public ImpexTransformerTask()
  • Method Details

    • execute

      Description copied from interface: HeaderTask
      Executes a task with a predefined BatchHeader identifying all relevant process information.
      Specified by:
      execute in interface HeaderTask
      Returns:
      the header
      Throws:
      UnsupportedEncodingException
      FileNotFoundException
    • convertFile

      protected boolean convertFile(BatchHeader header, File file, File impexFile, ImpexConverter converter) throws UnsupportedEncodingException, FileNotFoundException
      Converts the CSV file to an impex file using the given converter
      Parameters:
      header -
      file -
      impexFile -
      converter -
      Returns:
      true, if the file contains at least one converted row
      Throws:
      UnsupportedEncodingException
      FileNotFoundException
    • convertRow

      protected boolean convertRow(Long sequenceId, ImpexConverter converter, CSVReader csvReader, PrintWriter writer)
      Converts a single csv row and writes out
      Parameters:
      sequenceId - sequence id of the req to process
      converter - converter to convert the row
      csvReader - reader to read from
      writer - writer to write to
      Returns:
      true if the line could be converted false otherwise
    • getReplacedHeader

      protected String getReplacedHeader(BatchHeader header, ImpexConverter converter)
      Returns the header string with all defined replacements:
      • $STORE: store name
      • $CATALOG: full catalog name
      • $LANGUAGE$: the language defined in the filename, defaulted to a fallback language (e.g. en)
      • $NET: the net setting per catalog
      • $TYPE$: optional type setting to reuse converter definitions where only the type name changes (e.g. Product)
      Parameters:
      header -
      converter -
      Returns:
      header string with replacements
    • buildReplacementSymbols

      protected void buildReplacementSymbols(Map<String,String> symbols, BatchHeader header, ImpexConverter converter)
    • replaceSymbolsInText

      protected String replaceSymbolsInText(String text, Map<String,String> symbols)
    • writeErrorLine

      protected PrintWriter writeErrorLine(File file, CSVReader csvReader, PrintWriter errorWriter, IllegalArgumentException exc) throws UnsupportedEncodingException, FileNotFoundException
      Prints an error line containing the reason and the source line to the error file
      Parameters:
      file -
      csvReader -
      errorWriter -
      exc - the exception
      Returns:
      error writer
      Throws:
      UnsupportedEncodingException
      FileNotFoundException
    • createCsvReader

      protected CSVReader createCsvReader(File file) throws UnsupportedEncodingException, FileNotFoundException
      Creates a CSV Reader
      Parameters:
      file -
      Returns:
      a initialised CSV reader
      Throws:
      UnsupportedEncodingException
      FileNotFoundException
    • getImpexFile

      protected File getImpexFile(File file, int position)
      Returns the impex file
      Parameters:
      file -
      position - file position
      Returns:
      the impex file
    • getErrorFile

      protected File getErrorFile(File file)
      Returns the error file
      Parameters:
      file -
      Returns:
      the error file
    • getConverters

      protected List<ImpexConverter> getConverters(File file)
      Retrieves the converter for a file.
      Parameters:
      file -
      Returns:
      the configured converter
      Throws:
      IllegalArgumentException - if no converter was found
    • setEncoding

      public void setEncoding(String encoding)
      Parameters:
      encoding - the encoding to set
    • setLinesToSkip

      public void setLinesToSkip(int linesToSkip)
    • setFieldSeparator

      public void setFieldSeparator(char fieldSeparator)
      Parameters:
      fieldSeparator - the fieldSeparator to set
    • initConvertersMap

      public void initConvertersMap()
      Initializes by collecting all beans of type ConverterMapping
    • setConverterMap

      protected void setConverterMap(Map<String,List<ImpexConverter>> converterMap)
      Method for pure test usage, please use initConvertersMap() method
    • getConverterMap

      protected Map<String,List<ImpexConverter>> getConverterMap()
      Method for pure test usage, please use initConvertersMap() method
    • setCleanupHelper

      public void setCleanupHelper(CleanupHelper cleanupHelper)
      Parameters:
      cleanupHelper - the cleanupHelper to set
    • closeQuietly

      protected void closeQuietly(CSVReader csvReader)
    • setApplicationContext

      public void setApplicationContext(org.springframework.context.ApplicationContext appCtx) throws org.springframework.beans.BeansException
      Specified by:
      setApplicationContext in interface org.springframework.context.ApplicationContextAware
      Throws:
      org.springframework.beans.BeansException
    • getEncoding

      protected String getEncoding()
      Returns:
      the encoding
    • getLinesToSkip

      protected int getLinesToSkip()
      Returns:
      the linesToSkip
    • getFieldSeparator

      protected char getFieldSeparator()
      Returns:
      the fieldSeparator
    • getCleanupHelper

      protected CleanupHelper getCleanupHelper()
      Returns:
      the cleanupHelper