Package de.hybris.platform.cronjob.jalo
Class GenericCSVImportStep
- java.lang.Object
-
- de.hybris.platform.util.BridgeAbstraction
-
- de.hybris.platform.jalo.Item
-
- de.hybris.platform.jalo.ExtensibleItem
-
- de.hybris.platform.jalo.c2l.LocalizableItem
-
- de.hybris.platform.jalo.GenericItem
-
- de.hybris.platform.cronjob.jalo.GeneratedStep
-
- de.hybris.platform.cronjob.jalo.Step
-
- de.hybris.platform.cronjob.jalo.GeneratedMediaProcessorStep
-
- de.hybris.platform.cronjob.jalo.MediaProcessorStep
-
- de.hybris.platform.cronjob.jalo.GeneratedGenericCSVImportStep
-
- de.hybris.platform.cronjob.jalo.GenericCSVImportStep
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable
- Direct Known Subclasses:
GenericCSVImportStepTest.GenericCSVImportStepClon
public abstract class GenericCSVImportStep extends GeneratedGenericCSVImportStep
The abstractGenericCSVImportStep
offers a framework of methods to support the parsing of CSV files. Extend thisStep
to implement a CSV import for a specific CSV format. If the default tokenisation is sufficent (tokenise(String)
) for your file format, then you only have to implementprocessObjects(Map, CronJob)
.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class de.hybris.platform.jalo.GenericItem
GenericItem.GenericItemImpl
-
Nested classes/interfaces inherited from class de.hybris.platform.jalo.c2l.LocalizableItem
LocalizableItem.LocalizableItemImpl
-
Nested classes/interfaces inherited from class de.hybris.platform.jalo.ExtensibleItem
ExtensibleItem.ExtensibleItemImpl
-
Nested classes/interfaces inherited from class de.hybris.platform.jalo.Item
Item.AttributeFilter, Item.AttributeMode, Item.CachedGetter, Item.CachedSetter, Item.ItemAttributeMap, Item.ItemConstraint, Item.ItemImpl, Item.JaloCachedComputationException
-
-
Field Summary
-
Fields inherited from class de.hybris.platform.cronjob.jalo.GeneratedGenericCSVImportStep
DEFAULT_INITIAL_ATTRIBUTES
-
Fields inherited from class de.hybris.platform.cronjob.jalo.GeneratedStep
BATCHJOB, CODE, CRONJOBPENDINGSTEPSRELATION_MARKMODIFIED, CRONJOBPENDINGSTEPSRELATION_SRC_ORDERED, CRONJOBPENDINGSTEPSRELATION_TGT_ORDERED, CRONJOBPROCESSEDSTEPSRELATION_MARKMODIFIED, CRONJOBPROCESSEDSTEPSRELATION_SRC_ORDERED, CRONJOBPROCESSEDSTEPSRELATION_TGT_ORDERED, ERRORMODE, PENDINGCRONJOBS, PROCESSEDCRONJOBS, SEQUENCENUMBER, SYNCHRONOUS
-
Fields inherited from class de.hybris.platform.jalo.c2l.LocalizableItem
LANGUAGE_FALLBACK_ENABLED
-
Fields inherited from class de.hybris.platform.jalo.Item
_CREATION_TIME_INTERNAL, _MODIFIED_TIME_INTERNAL, accessorLog, CREATION_TIME, DISABLE_ATTRIBUTE_CHECK, DISABLE_ITEMCHECK_BEFORE_REMOVABLE, EVEN, FEATURE_ACCESSMAP_QUALIFIER, HJMPTS, INITIAL_CREATION_FLAG, isJaloOnly, MODIFIED_TIME, NEGATIVE, NOT_FOUND, OWNER, PK, POSITIVE, SAVE_FROM_SERVICE_LAYER, staticTransientObjects, TYPE
-
Fields inherited from class de.hybris.platform.util.BridgeAbstraction
impl, tenant
-
-
Constructor Summary
Constructors Constructor Description GenericCSVImportStep()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected void
checkAbort(CronJob cronJob)
protected CSVReader
createCSVReader(java.io.InputStream inputStream, java.lang.String encoding)
As default creates a newCSVReader
instance with the given stream and encoding.protected void
finalizeStep(CronJob cronJob)
Method for finalizing the step.protected java.lang.String
getCharSet()
define the character set for the performStep() method.protected char[]
getCommentOutCharacters()
Returns a char array with of all comment tokens.protected char[]
getTokenCharacters()
Returns a character array witch is used as value seperator token.boolean
isAbortable()
Returnstrue
, if thisStep
is abortable.protected java.io.InputStream
openMedia(JobMedia media, CronJob cronJob)
Opens anInputStream
to theJobMedia
of the specifiedCronJob
.protected void
performStep(CronJob cronJob)
Opens the batch media provided by the given job detail and iterates over all lines.protected boolean
processLine(java.lang.String line, CronJob cronJob)
Deprecated.since ages - no longer needed - just overrideprocessObjects(Map, CronJob)
to handle a tokenized line orcreateCSVReader(InputStream, String)
to define own tokenizing logic.protected abstract boolean
processObjects(java.util.Map map, CronJob cronJob)
Processes one parsed csv line.protected boolean
skipFirstLine()
Returnstrue
, if the first line of the file should be skipped.protected java.util.Map
tokenise(java.lang.String line)
Deprecated.since ages - to override line tokenizing usecreateCSVReader(InputStream, String)
!-
Methods inherited from class de.hybris.platform.cronjob.jalo.GeneratedGenericCSVImportStep
getDefaultAttributeModes
-
Methods inherited from class de.hybris.platform.cronjob.jalo.MediaProcessorStep
canPerform, prepareMedia
-
Methods inherited from class de.hybris.platform.cronjob.jalo.Step
addChange, canUndo, createItem, debug, error, fatal, getChanges, getChanges, getChanges, getChanges, getFailErrorMode, getIgnoreErrorMode, getMostRecentChange, getNonInitialAttributes, getPauseErrorMode, hasChanges, info, isDebugEnabled, isErrorEnabled, isInfoEnabled, isWarnEnabled, log, setNonInitialAttributes, toString, undoStep, warn
-
Methods inherited from class de.hybris.platform.cronjob.jalo.GeneratedStep
getBatchJob, getBatchJob, getCode, getCode, getErrorMode, getErrorMode, getSequenceNumber, getSequenceNumber, getSequenceNumberAsPrimitive, getSequenceNumberAsPrimitive, isMarkModifiedDisabled, isSynchronous, isSynchronous, isSynchronousAsPrimitive, isSynchronousAsPrimitive, setBatchJob, setBatchJob, setCode, setCode, setErrorMode, setErrorMode, setSequenceNumber, setSequenceNumber, setSequenceNumber, setSequenceNumber, setSynchronous, setSynchronous, setSynchronous, setSynchronous
-
Methods inherited from class de.hybris.platform.jalo.GenericItem
getImplementation, getInitialProperties, getRelatedItems, setRelatedItems
-
Methods inherited from class de.hybris.platform.jalo.c2l.LocalizableItem
getAllLocalizedProperties, getAllLocalizedProperties, getAllLocalizedProperties, getAllLocalizedProperties, getAllValuesSessionContext, getLocalizedProperty, getLocalizedProperty, getLocalizedPropertyInternal, getLocalizedPropertyNames, getLocalizedPropertyNames, hasLanguage, isEmptyValue, isFallbackEnabled, removeLocalizedProperty, removeLocalizedProperty, setAllLocalizedProperties, setAllLocalizedProperties, setLocalizedProperty, setLocalizedProperty
-
Methods inherited from class de.hybris.platform.jalo.ExtensibleItem
createNonClassAccessor, getAllProperties, getAllProperties, getProperty, getProperty, getPropertyNames, getPropertyNames, removeProperty, removeProperty, setAllProperties, setAllProperties, setProperty, setProperty
-
Methods inherited from class de.hybris.platform.jalo.Item
addLinkedItems, addLinkedItems, addLinkedItems, addLinkedItems, addLinkedItems, addLinkedItems, addLinkedItems, addLinkedItems, addLinkedItems, addNegativePermission, addPermission, addPositivePermission, assureExtensionsLoaded, changeTypeAfterCreation, checkConstraint, checkItemPermission, checkMandatoryAttribute, checkMandatoryAttribute, checkPermission, checkPermission, checkRemovable, clearPermission, compareTo, ctx, doAfterRemove, doBeforeRemove, equals, getAccessorFor, getAllAttributes, getAllAttributes, getAllAttributes, getAllAttributes, getAllAttributesInternal, getAllLinkedItems, getAndCheckCacheBoundItem, getAttribute, getAttribute, getCacheBoundItem, getComposedType, getComposedTypePK, getCreationTime, getCurrentlyRemovingCount, getLinkedItems, getLinkedItems, getLinkedItems, getLinkedItems, getLinkedItems, getLinkedItems, getLinkedItems, getLinkedItemsCount, getLinkedItemsCount, getLinkedItemsCount, getModificationTime, getNegativePermissions, getOwner, getPermissionMap, getPermissions, getPersistenceVersion, getPK, getPositivePermissions, getRestrictedPrincipals, getSession, getSyncObject, getTenant, getTransientObject, getTransientObjectMap, hashCode, hasRegisteredClassAccessorFor, internal_registerClassAccessorFor, internal_registerNonClassAccessorFor, invalidateLocalCaches, isAlive, isCacheBound, isCurrentlyRemoving, isCurrentlyRemoving, isEmptyRelationValue, isInCreate, isInstanceOf, isItemCheckBeforeRemoveableDisabled, isRelationLocalizationFallbackEnabled, newInstance, notifyExtensionsAfterItemCreation, notifyExtensionsBeforeItemCreation, notifyItemRemoval, notifyManagerAboutItemRemoval, readResolve, registerAccessFor, registerAccessFor, registerJaloInvalidationListeners, remove, remove, removeItemCollection, removeItemCollection, removeLinkedItems, removeLinkedItems, removeLinkedItems, removeLinkedItems, removeLinks, removePartOfItems, removePartOfItems, setAllAttributes, setAllAttributes, setAllAttributesInternal, setAllLinkedItems, setAllLinkedItems, setAllLinkedItems, setAllLinkedItems, setAttribute, setAttribute, setAttributeFromString, setAttributeFromString, setCacheBound, setComposedType, setCreationTime, setImplementation, setLinkedItems, setLinkedItems, setLinkedItems, setLinkedItems, setLinkedItems, setLinkedItems, setLinkedItems, setLinkedItems, setModificationTime, setOwner, setPermissionsByMap, setTransientObject, setUseTA, useTA, writeReplace
-
Methods inherited from class de.hybris.platform.util.BridgeAbstraction
setTenant
-
-
-
-
Method Detail
-
processObjects
protected abstract boolean processObjects(java.util.Map map, CronJob cronJob) throws JaloBusinessException
Processes one parsed csv line. This method must be implemented by concrete subclasses which transforms this data.- Parameters:
map
- the data of the line as aMap
Integer
->String
- the key contains the column index staring with0
cronJob
-- Returns:
- boolean returns
true
if processing has succeeded - the job will continue regardless of this result - Throws:
JaloBusinessException
- may be thrown to indicate a process error - the job will abort after this line
-
finalizeStep
protected void finalizeStep(CronJob cronJob) throws JaloBusinessException
Method for finalizing the step. Is called after all lines were processed.- Parameters:
cronJob
-- Throws:
JaloBusinessException
-
skipFirstLine
protected boolean skipFirstLine()
Returnstrue
, if the first line of the file should be skipped. This default implementation returnsfalse
. Overwrite this method in your subclass, to change this default implementation.- Returns:
true
, if the first line of the file should be skipped
-
processLine
@Deprecated protected final boolean processLine(java.lang.String line, CronJob cronJob) throws JaloBusinessException, AbortCronJobException
Deprecated.since ages - no longer needed - just overrideprocessObjects(Map, CronJob)
to handle a tokenized line orcreateCSVReader(InputStream, String)
to define own tokenizing logic.
-
getTokenCharacters
protected char[] getTokenCharacters()
Returns a character array witch is used as value seperator token.As default
CronJobConstants.CHARS.VERTICAL_LINE
( '|' ) is used. Override this method to specify a different separator token.- Returns:
- a char array with of all token characters
-
getCommentOutCharacters
protected char[] getCommentOutCharacters()
Returns a char array with of all comment tokens. Each line starting with one of this tokens is considered as comment and will be ignored.As default this method returns
CronJobConstants.CHARS.POUND
+CronJobConstants.CHARS.PERCENT
( '#%' ). Override to specify a different token.- Returns:
- a char array with of all comment tokens
-
createCSVReader
protected CSVReader createCSVReader(java.io.InputStream inputStream, java.lang.String encoding) throws java.io.UnsupportedEncodingException
As default creates a newCSVReader
instance with the given stream and encoding. Override when own parsing and tokenizing logic is needed.- Parameters:
inputStream
- the csv data input streamencoding
- the text encoding of the csv data stream- Returns:
- a new reader instance
- Throws:
java.io.UnsupportedEncodingException
- if the given encoding is not supported
-
performStep
protected void performStep(CronJob cronJob) throws AbortCronJobException, JaloInvalidParameterException
Opens the batch media provided by the given job detail and iterates over all lines. Therefore this method will callMediaProcessorStep.prepareMedia(CronJob)
at the beginning,openMedia(JobMedia, CronJob)
to open the input stream andprocessLine(String, CronJob)
for each line which is read. FinallyfinalizeStep(CronJob)
is called after all lines are read.- Specified by:
performStep
in classStep
- Parameters:
cronJob
- the CronJob which this step if performed for - must be aMediaProcessCronJob
instance- Throws:
AbortCronJobException
- if a abort request has been detectedJaloInvalidParameterException
- in case the job detail is no instance ofMediaProcessCronJob
- See Also:
Step.canPerform(CronJob)
-
getCharSet
protected java.lang.String getCharSet()
define the character set for the performStep() method.- Returns:
- the charset which should be used, default is "UTF-8"
- Since:
- 2.10
-
openMedia
protected java.io.InputStream openMedia(JobMedia media, CronJob cronJob) throws JaloBusinessException, java.io.IOException
Opens anInputStream
to theJobMedia
of the specifiedCronJob
.This default implementation used
Media.getDataFromStream()
to open the stream to the media. Subclasses may override this e.g. to support zip file medias or similar.- Parameters:
media
- theJobMedia
which will be openedcronJob
- theCronJob
which thisStep
is executed for- Returns:
- the
DataInputStream
to the specifiedJobMedia
- Throws:
JaloBusinessException
java.io.IOException
-
tokenise
@Deprecated protected final java.util.Map tokenise(java.lang.String line)
Deprecated.since ages - to override line tokenizing usecreateCSVReader(InputStream, String)
!
-
isAbortable
public boolean isAbortable()
Description copied from class:Step
Returnstrue
, if thisStep
is abortable.The default implementation returns always
false
. To mark yourStep
subclass as abortable, override this method and returntrue
.- Overrides:
isAbortable
in classStep
- Returns:
true
, if thisStep
is abortable- See Also:
Step.isAbortable()
-
checkAbort
protected void checkAbort(CronJob cronJob) throws AbortCronJobException
- Throws:
AbortCronJobException
-
-