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:
Serializable,Comparable
- Direct Known Subclasses:
GenericCSVImportStepTest.GenericCSVImportStepClon
The abstract
GenericCSVImportStep offers a framework of methods to support the parsing of CSV files.
Extend this Step 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
implement processObjects(Map, CronJob).
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class de.hybris.platform.jalo.GenericItem
GenericItem.GenericItemImplNested classes/interfaces inherited from class de.hybris.platform.jalo.c2l.LocalizableItem
LocalizableItem.LocalizableItemImplNested classes/interfaces inherited from class de.hybris.platform.jalo.ExtensibleItem
ExtensibleItem.ExtensibleItemImplNested 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_ATTRIBUTESFields 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, SYNCHRONOUSFields inherited from class de.hybris.platform.jalo.c2l.LocalizableItem
LANGUAGE_FALLBACK_ENABLEDFields 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, TYPEFields inherited from class de.hybris.platform.util.BridgeAbstraction
impl, tenant -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheckAbort(CronJob cronJob) protected CSVReadercreateCSVReader(InputStream inputStream, String encoding) As default creates a newCSVReaderinstance with the given stream and encoding.protected voidfinalizeStep(CronJob cronJob) Method for finalizing the step.protected Stringdefine the character set for the performStep() method.protected char[]Returns a char array with of all comment tokens.protected char[]Returns a character array witch is used as value seperator token.booleanReturnstrue, if thisStepis abortable.protected InputStreamOpens anInputStreamto theJobMediaof the specifiedCronJob.protected voidperformStep(CronJob cronJob) Opens the batch media provided by the given job detail and iterates over all lines.protected final booleanprocessLine(String line, CronJob cronJob) Deprecated.protected abstract booleanprocessObjects(Map map, CronJob cronJob) Processes one parsed csv line.protected booleanReturnstrue, if the first line of the file should be skipped.protected final MapDeprecated.since ages - to override line tokenizing usecreateCSVReader(InputStream, String)!Methods inherited from class de.hybris.platform.cronjob.jalo.GeneratedGenericCSVImportStep
getDefaultAttributeModesMethods inherited from class de.hybris.platform.cronjob.jalo.MediaProcessorStep
canPerform, prepareMediaMethods 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, warnMethods 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, setSynchronousMethods inherited from class de.hybris.platform.jalo.GenericItem
getImplementation, getInitialProperties, getRelatedItems, getRelatedItems, setRelatedItemsMethods 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, setLocalizedPropertyMethods inherited from class de.hybris.platform.jalo.ExtensibleItem
createNonClassAccessor, getAllProperties, getAllProperties, getProperty, getProperty, getPropertyNames, getPropertyNames, removeProperty, removeProperty, setAllProperties, setAllProperties, setProperty, setPropertyMethods 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, getPartOfRemovedSessionMarker, 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, suppressRelation, useTA, writeReplaceMethods inherited from class de.hybris.platform.util.BridgeAbstraction
setTenant
-
Constructor Details
-
GenericCSVImportStep
public GenericCSVImportStep()
-
-
Method Details
-
processObjects
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 aMapInteger->String- the key contains the column index staring with0cronJob-- Returns:
- boolean returns
trueif 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
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(since="ages", forRemoval=false) protected final boolean processLine(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(InputStream inputStream, String encoding) throws UnsupportedEncodingException As default creates a newCSVReaderinstance 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:
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:
performStepin classStep- Parameters:
cronJob- the CronJob which this step if performed for - must be aMediaProcessCronJobinstance- Throws:
AbortCronJobException- if a abort request has been detectedJaloInvalidParameterException- in case the job detail is no instance ofMediaProcessCronJob- See Also:
-
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 InputStream openMedia(JobMedia media, CronJob cronJob) throws JaloBusinessException, IOException Opens anInputStreamto theJobMediaof 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- theJobMediawhich will be openedcronJob- theCronJobwhich thisStepis executed for- Returns:
- the
DataInputStreamto the specifiedJobMedia - Throws:
JaloBusinessExceptionIOException
-
tokenise
Deprecated.since ages - to override line tokenizing usecreateCSVReader(InputStream, String)! -
isAbortable
public boolean isAbortable()Description copied from class:StepReturnstrue, if thisStepis abortable.The default implementation returns always
false. To mark yourStepsubclass as abortable, override this method and returntrue.- Overrides:
isAbortablein classStep- Returns:
true, if thisStepis abortable- See Also:
-
checkAbort
- Throws:
AbortCronJobException
-
processObjects(Map, CronJob)to handle a tokenized line orcreateCSVReader(InputStream, String)to define own tokenizing logic.