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 java.lang.Object implements HeaderTask, org.springframework.context.ApplicationContextAware
Transformer that retrieves a CSV file and transforms it to an impex file.
-
-
Constructor Summary
Constructors Constructor Description ImpexTransformerTask()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidbuildReplacementSymbols(java.util.Map<java.lang.String,java.lang.String> symbols, BatchHeader header, ImpexConverter converter)protected voidcloseQuietly(CSVReader csvReader)protected booleanconvertFile(BatchHeader header, java.io.File file, java.io.File impexFile, ImpexConverter converter)Converts the CSV file to an impex file using the given converterprotected CSVReadercreateCsvReader(java.io.File file)Creates a CSV ReaderBatchHeaderexecute(BatchHeader header)Executes a task with a predefinedBatchHeaderidentifying all relevant process information.protected CleanupHelpergetCleanupHelper()protected java.util.Map<java.lang.String,java.util.List<ImpexConverter>>getConverterMap()Method for pure test usage, please useinitConvertersMap()methodprotected java.util.List<ImpexConverter>getConverters(java.io.File file)Retrieves the converter for a file.protected java.lang.StringgetEncoding()protected java.io.FilegetErrorFile(java.io.File file)Returns the error fileprotected chargetFieldSeparator()protected java.io.FilegetImpexFile(java.io.File file, int position)Returns the impex fileprotected intgetLinesToSkip()protected java.lang.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.voidinitConvertersMap()Initializes by collecting all beans of typeConverterMappingprotected java.lang.StringreplaceSymbolsInText(java.lang.String text, java.util.Map<java.lang.String,java.lang.String> symbols)voidsetApplicationContext(org.springframework.context.ApplicationContext appCtx)voidsetCleanupHelper(CleanupHelper cleanupHelper)protected voidsetConverterMap(java.util.Map<java.lang.String,java.util.List<ImpexConverter>> converterMap)Method for pure test usage, please useinitConvertersMap()methodvoidsetEncoding(java.lang.String encoding)voidsetFieldSeparator(char fieldSeparator)voidsetLinesToSkip(int linesToSkip)protected java.io.PrintWriterwriteErrorLine(java.io.File file, CSVReader csvReader, java.io.PrintWriter errorWriter, java.lang.IllegalArgumentException exc)Prints an error line containing the reason and the source line to the error file
-
-
-
Method Detail
-
execute
public BatchHeader execute(BatchHeader header) throws java.io.UnsupportedEncodingException, java.io.FileNotFoundException
Description copied from interface:HeaderTaskExecutes a task with a predefinedBatchHeaderidentifying all relevant process information.- Specified by:
executein interfaceHeaderTask- Returns:
- the header
- Throws:
java.io.UnsupportedEncodingExceptionjava.io.FileNotFoundException
-
convertFile
protected boolean convertFile(BatchHeader header, java.io.File file, java.io.File impexFile, ImpexConverter converter) throws java.io.UnsupportedEncodingException, java.io.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:
java.io.UnsupportedEncodingExceptionjava.io.FileNotFoundException
-
getReplacedHeader
protected java.lang.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(java.util.Map<java.lang.String,java.lang.String> symbols, BatchHeader header, ImpexConverter converter)
-
replaceSymbolsInText
protected java.lang.String replaceSymbolsInText(java.lang.String text, java.util.Map<java.lang.String,java.lang.String> symbols)
-
writeErrorLine
protected java.io.PrintWriter writeErrorLine(java.io.File file, CSVReader csvReader, java.io.PrintWriter errorWriter, java.lang.IllegalArgumentException exc) throws java.io.UnsupportedEncodingException, java.io.FileNotFoundExceptionPrints 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:
java.io.UnsupportedEncodingExceptionjava.io.FileNotFoundException
-
createCsvReader
protected CSVReader createCsvReader(java.io.File file) throws java.io.UnsupportedEncodingException, java.io.FileNotFoundException
Creates a CSV Reader- Parameters:
file-- Returns:
- a initialised CSV reader
- Throws:
java.io.UnsupportedEncodingExceptionjava.io.FileNotFoundException
-
getImpexFile
protected java.io.File getImpexFile(java.io.File file, int position)Returns the impex file- Parameters:
file-position- file position- Returns:
- the impex file
-
getErrorFile
protected java.io.File getErrorFile(java.io.File file)
Returns the error file- Parameters:
file-- Returns:
- the error file
-
getConverters
protected java.util.List<ImpexConverter> getConverters(java.io.File file)
Retrieves the converter for a file.- Parameters:
file-- Returns:
- the configured converter
- Throws:
java.lang.IllegalArgumentException- if no converter was found
-
setEncoding
public void setEncoding(java.lang.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 typeConverterMapping
-
setConverterMap
protected void setConverterMap(java.util.Map<java.lang.String,java.util.List<ImpexConverter>> converterMap)
Method for pure test usage, please useinitConvertersMap()method
-
getConverterMap
protected java.util.Map<java.lang.String,java.util.List<ImpexConverter>> getConverterMap()
Method for pure test usage, please useinitConvertersMap()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:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware- Throws:
org.springframework.beans.BeansException
-
getEncoding
protected java.lang.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
-
-