Class ImpexTransformerTask
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidbuildReplacementSymbols(Map<String, String> symbols, BatchHeader header, ImpexConverter converter) protected voidcloseQuietly(CSVReader csvReader) protected booleanconvertFile(BatchHeader header, File file, File impexFile, ImpexConverter converter) Converts the CSV file to an impex file using the given converterprotected booleanconvertRow(Long sequenceId, ImpexConverter converter, CSVReader csvReader, PrintWriter writer) Converts a single csv row and writes outprotected CSVReadercreateCsvReader(File file) Creates a CSV Readerexecute(BatchHeader header) Executes a task with a predefinedBatchHeaderidentifying all relevant process information.protected CleanupHelperprotected Map<String,List<ImpexConverter>> Method for pure test usage, please useinitConvertersMap()methodprotected List<ImpexConverter>getConverters(File file) Retrieves the converter for a file.protected Stringprotected FilegetErrorFile(File file) Returns the error fileprotected charprotected FilegetImpexFile(File file, int position) Returns the impex fileprotected intprotected StringgetReplacedHeader(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.voidInitializes by collecting all beans of typeConverterMappingprotected StringreplaceSymbolsInText(String text, Map<String, String> symbols) voidsetApplicationContext(org.springframework.context.ApplicationContext appCtx) voidsetCleanupHelper(CleanupHelper cleanupHelper) protected voidsetConverterMap(Map<String, List<ImpexConverter>> converterMap) Method for pure test usage, please useinitConvertersMap()methodvoidsetEncoding(String encoding) voidsetFieldSeparator(char fieldSeparator) voidsetLinesToSkip(int linesToSkip) protected PrintWriterwriteErrorLine(File file, CSVReader csvReader, PrintWriter errorWriter, IllegalArgumentException exc) Prints an error line containing the reason and the source line to the error file
-
Constructor Details
-
ImpexTransformerTask
public ImpexTransformerTask()
-
-
Method Details
-
execute
public BatchHeader execute(BatchHeader header) throws UnsupportedEncodingException, FileNotFoundException Description copied from interface:HeaderTaskExecutes a task with a predefinedBatchHeaderidentifying all relevant process information.- Specified by:
executein interfaceHeaderTask- Returns:
- the header
- Throws:
UnsupportedEncodingExceptionFileNotFoundException
-
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:
UnsupportedEncodingExceptionFileNotFoundException
-
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 processconverter- converter to convert the rowcsvReader- reader to read fromwriter- writer to write to- Returns:
- true if the line could be converted false otherwise
-
getReplacedHeader
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
-
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:
UnsupportedEncodingExceptionFileNotFoundException
-
createCsvReader
protected CSVReader createCsvReader(File file) throws UnsupportedEncodingException, FileNotFoundException Creates a CSV Reader- Parameters:
file-- Returns:
- a initialised CSV reader
- Throws:
UnsupportedEncodingExceptionFileNotFoundException
-
getImpexFile
Returns the impex file- Parameters:
file-position- file position- Returns:
- the impex file
-
getErrorFile
Returns the error file- Parameters:
file-- Returns:
- the error file
-
getConverters
Retrieves the converter for a file.- Parameters:
file-- Returns:
- the configured converter
- Throws:
IllegalArgumentException- if no converter was found
-
setEncoding
- 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 typeConverterMapping -
setConverterMap
Method for pure test usage, please useinitConvertersMap()method -
getConverterMap
Method for pure test usage, please useinitConvertersMap()method -
setCleanupHelper
- Parameters:
cleanupHelper- the cleanupHelper to set
-
closeQuietly
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext appCtx) throws org.springframework.beans.BeansException - Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware- Throws:
org.springframework.beans.BeansException
-
getEncoding
- Returns:
- the encoding
-
getLinesToSkip
protected int getLinesToSkip()- Returns:
- the linesToSkip
-
getFieldSeparator
protected char getFieldSeparator()- Returns:
- the fieldSeparator
-
getCleanupHelper
- Returns:
- the cleanupHelper
-