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 void
buildReplacementSymbols(java.util.Map<java.lang.String,java.lang.String> symbols, BatchHeader header, ImpexConverter converter)
protected void
closeQuietly(CSVReader csvReader)
protected boolean
convertFile(BatchHeader header, java.io.File file, java.io.File impexFile, ImpexConverter converter)
Converts the CSV file to an impex file using the given converterprotected CSVReader
createCsvReader(java.io.File file)
Creates a CSV ReaderBatchHeader
execute(BatchHeader header)
Executes a task with a predefinedBatchHeader
identifying all relevant process information.protected CleanupHelper
getCleanupHelper()
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.String
getEncoding()
protected java.io.File
getErrorFile(java.io.File file)
Returns the error fileprotected char
getFieldSeparator()
protected java.io.File
getImpexFile(java.io.File file, int position)
Returns the impex fileprotected int
getLinesToSkip()
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.void
initConvertersMap()
Initializes by collecting all beans of typeConverterMapping
protected java.lang.String
replaceSymbolsInText(java.lang.String text, java.util.Map<java.lang.String,java.lang.String> symbols)
void
setApplicationContext(org.springframework.context.ApplicationContext appCtx)
void
setCleanupHelper(CleanupHelper cleanupHelper)
protected void
setConverterMap(java.util.Map<java.lang.String,java.util.List<ImpexConverter>> converterMap)
Method for pure test usage, please useinitConvertersMap()
methodvoid
setEncoding(java.lang.String encoding)
void
setFieldSeparator(char fieldSeparator)
void
setLinesToSkip(int linesToSkip)
protected java.io.PrintWriter
writeErrorLine(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:HeaderTask
Executes a task with a predefinedBatchHeader
identifying all relevant process information.- Specified by:
execute
in interfaceHeaderTask
- Returns:
- the header
- Throws:
java.io.UnsupportedEncodingException
java.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.UnsupportedEncodingException
java.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.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:
java.io.UnsupportedEncodingException
java.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.UnsupportedEncodingException
java.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:
setApplicationContext
in 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
-
-