Class HeaderDescriptor

java.lang.Object
de.hybris.platform.impex.jalo.header.AbstractDescriptor
de.hybris.platform.impex.jalo.header.HeaderDescriptor

public class HeaderDescriptor extends AbstractDescriptor
Represents an header line within an ImpEx script. It mainly consists of the header mode, the configured composed type and a list of configured columns.
  • Constructor Details

    • HeaderDescriptor

      public HeaderDescriptor(ImpExReader reader, String expr, List<String> columnExpressions, String location, DocumentIDRegistry docIDRegistry) throws HeaderValidationException
      Self-parsing constructor - Creates a new header instance. Use this constructor if you have a header line as list of Strings. Determines header params, the configured composed type, the permitted types, the configured columns, the default composed type and determines the correct positions of the columns.
      Parameters:
      reader - calling reader instance mainly for logging purposes
      expr - the first record entry of the header line
      columnExpressions - list of all further records (columns) of header line
      location - current location of used reader
      docIDRegistry - registry used for storing used documents IDs
      Throws:
      HeaderValidationException - error while determining and checking type and columns
    • HeaderDescriptor

      public HeaderDescriptor(ImpExReader reader, String expr, AbstractDescriptor.DescriptorParams headerParams, String location, DocumentIDRegistry docIDRegistry) throws HeaderValidationException
      Non-parsing constructor - Creates a new header instance. Use this constructor if you get the header line column by column. Determines the configured composed type. Columns will not be checked and determined as well as other tasks depending on that step.. Please call setColumns(List) later for performing these missing steps.
      Parameters:
      reader - calling reader instance mainly for logging purposes
      expr - the first record entry of the header line
      headerParams - already parsed params of header
      location - current location of used reader
      docIDRegistry - registry used for storing used documents IDs
      Throws:
      HeaderValidationException - error while determining and checking type and columns
    • HeaderDescriptor

      public HeaderDescriptor(ImpExReader reader, String expr, List<String> columnExpressions, String location, DocumentIDRegistry docIDRegistry, HeaderValidationException headerException) throws HeaderValidationException
      Throws:
      HeaderValidationException
  • Method Details

    • isValid

      public boolean isValid()
      True, if valid
      Returns:
      true if header is valid
    • getInvalidHeaderException

      public HeaderValidationException getInvalidHeaderException()
      Gets exception associated with invalid header or null if header is valid.
      Returns:
      exception or null if valid
    • setColumns

      public void setColumns(List<AbstractColumnDescriptor> columnDescriptors) throws HeaderValidationException
      Sets the columns of this header and triggers depending steps like Determination of the permitted types, the configured columns and the correct positions of the columns. Can only be called once!!
      Parameters:
      columnDescriptors - list of all column descriptors for this header
      Throws:
      HeaderValidationException - error while determining and checking columns
    • adjustValuePositions

      protected void adjustValuePositions() throws HeaderValidationException
      Discovers all virtual columns and removes them from the column range [0,x]. All virtual columns are set to the position -1 * position . Furthermore it maps each column to the column position defined by modifier 'pos' (if used). If the modifier is used for one column then it has to be used for each other column, for avoiding position conflicts. Furthermore, the defined position has to be unique.
      Throws:
      HeaderValidationException - Modifier position is not used consequently by all or nothing columns, or two position modifiers have the same value
    • getReader

      public ImpExReader getReader()
      Gets the reader instance which had created this header. Mainly used for logging purposes.
      Returns:
      reader which had created this header
    • isDebugEnabled

      @Deprecated(since="ages", forRemoval=false) public boolean isDebugEnabled()
      Deprecated.
      since ages - use logging methodCategory.isDebugEnabled() directly
      Checks if the debug method of the reader is enabled or if no reader set the logger will be checked.
      Returns:
      is debug mode enabled?
    • debug

      @Deprecated(since="ages", forRemoval=false) public void debug(String msg)
      Deprecated.
      since ages - use logging methodCategory.debug(Object) directly
      Debugs a message with the reader or the current logger instance.
      Parameters:
      msg - debug message
    • isInfoEnabled

      @Deprecated(since="ages", forRemoval=false) public boolean isInfoEnabled()
      Deprecated.
      since ages - use logging methodCategory.isInfoEnabled() directly
      Checks if the info method of the reader is enabled or if no reader set the logger will be checked.
      Returns:
      is info mode enabled?
    • info

      @Deprecated(since="ages", forRemoval=false) public void info(String msg)
      Deprecated.
      since ages - use logging methodCategory.info(Object) directly
      Logs an info message with the reader or the current logger instance.
      Parameters:
      msg - info message
    • warn

      @Deprecated(since="ages", forRemoval=false) public void warn(String msg)
      Deprecated.
      since ages - use logging methodCategory.warn(Object) directly
      Logs an warn message with the reader or the current logger instance.
      Parameters:
      msg - warn message
    • error

      @Deprecated(since="ages", forRemoval=false) public void error(String msg)
      Deprecated.
      since ages - use logging methodCategory.error(Object) directly
      Logs an error message with the reader or the current logger instance.
      Parameters:
      msg - error message
    • createTranslator

      protected HeaderCellTranslator createTranslator(String expr)
      Description copied from class: AbstractDescriptor
      Creates the translator class which parses the own definition text of this descriptor.
      Specified by:
      createTranslator in class AbstractDescriptor
      Parameters:
      expr - the definition text
      Returns:
      the translator instance
    • isBatchMode

      public boolean isBatchMode()
      Checks if the batch modifier is set for this header.
      Returns:
      true if batch=true is set for header, false otherwise
    • isInsertMode

      public boolean isInsertMode()
      Checks whether the header mode is INSERT.
      Returns:
      true if header mode is INSERT, false otherwise
    • isUpdateMode

      public boolean isUpdateMode()
      Checks whether the header mode is UPDATE.
      Returns:
      true if header mode is UPDATE, false otherwise
    • isInsertUpdateMode

      public boolean isInsertUpdateMode()
      Checks whether the header mode is INSERT_UPDATE.
      Returns:
      true if header mode is INSERT_UPDATE, false otherwise
    • isRemoveMode

      public boolean isRemoveMode()
      Checks whether the header mode is REMOVE.
      Returns:
      true if header mode is REMOVE, false otherwise
    • getColumns

      public List<AbstractColumnDescriptor> getColumns()
      Gets the column descriptors configured for this header.
      Returns:
      list of all configured column descriptors
    • getNumCols

      public int getNumCols()
    • getSpecificColumns

      public <T extends AbstractColumnDescriptor> Collection<T> getSpecificColumns(Class<T> descriptor)
      Returns a collection of all column descriptors instances which are instance of the given descriptor class. With that you can get for example all special columns.
      Type Parameters:
      T - Type of column descriptors the result will contain (will be filtered)
      Parameters:
      descriptor - the class of which the descriptors have top be an instance of
      Returns:
      a collection of objects which are instances of the given class
    • getTypeCode

      public String getTypeCode()
      Gets the code of the configured composed type of header.
      Returns:
      code of configured composed type
    • findConfiguredComposedType

      protected ComposedType findConfiguredComposedType() throws HeaderValidationException
      Tries to gather the composed type instance configured in header line.
      Returns:
      the composed type configured at header line
      Throws:
      HeaderValidationException - configured type is not existent at type system
    • getConfiguredComposedType

      public ComposedType getConfiguredComposedType()
      Returns the configured composed type, regardless of whether or not it is actually permitted by this header. To get the top-most permitted type use getDefaultComposedType().
      Returns:
      the configured composed type instance
    • getConfiguredComposedTypeCode

      public String getConfiguredComposedTypeCode()
      Returns the configured composed type, regardless of whether or not it is actually permitted by this header. To get the top-most permitted type use getDefaultComposedType().
      Returns:
      the configured composed type instance
    • calculateDefaultComposedType

      protected ComposedType calculateDefaultComposedType()
      Calculates the top-most permitted composed type starting at configured type. Gets the configured composed type if it is permitted (see isPermittedType(ComposedType)) and not abstract and not jalo, it will be used, else the subtypes will be searched until a type is found which fits the condition. The check of the subtypes is done as in breath depth search.
      Returns:
      the top-most permitted composed type starting at configured one
    • getDefaultComposedType

      public ComposedType getDefaultComposedType()
      Gets the top-most permitted composed type starting at configured type (see calculateDefaultComposedType() .
      Returns:
      the top-most permitted composed type starting at configured one
    • isDefaultComposedTypeSingleton

      public boolean isDefaultComposedTypeSingleton()
      Returns whether the default composed type getDefaultComposedType() is a singleton. Does no NullPointerException check.
    • getDefaultComposedTypeCode

      public String getDefaultComposedTypeCode()
      Gets the top-most permitted composed type starting at configured type (see calculateDefaultComposedType() .
      Returns:
      the top-most permitted composed type starting at configured one
    • getPermittedTypeCodes

      public Set<String> getPermittedTypeCodes()
      Gets the codes of all types which are subtypes of the configured one and have passed all checks of the calculatePermittedType(ComposedType) method.
      Returns:
      codes of all permitted types
    • isPermittedType

      public boolean isPermittedType(ComposedType ct)
      Checks whether the given type is permitted by this header (is subtype of configured one and fits all checks of calculatePermittedType(ComposedType)).
      Parameters:
      ct - type to check for permitted type
      Returns:
      true if given type is permitted by this header, false otherwise
    • isPermittedTypeForInsert

      @Deprecated(since="ages", forRemoval=false) public boolean isPermittedTypeForInsert(ComposedType ct)
      Deprecated.
      since ages - @deprecated useisPermittedTypeForInsert(String)
      Checks whether the given type is permitted by this header (is subtype of configured one and fits all checks of calculatePermittedType(ComposedType)) for inserts in INSERT or INSERT_UPDATE modes.

      Permits only when the type can be found in the permitted types and the type is not marked only for updates (see also HeaderDescriptor.PermittedTypeMapping.isOnlyForUpdate()).

      Parameters:
      ct - type to check for permitted type
      Returns:
      true if given type is permitted by this header, false otherwise
    • isPermittedTypeForInsert

      public boolean isPermittedTypeForInsert(String ct)
      Checks whether the given type is permitted by this header (is subtype of configured one and fits all checks of calculatePermittedType(ComposedType)) for inserts in INSERT or INSERT_UPDATE modes.

      Permits only when the type can be found in the permitted types and the type is not marked only for updates (see also HeaderDescriptor.PermittedTypeMapping.isOnlyForUpdate()).

      Parameters:
      ct - type to check for permitted type
      Returns:
      true if given type is permitted by this header, false otherwise
    • isPermittedTypeForUpdate

      @Deprecated(since="ages", forRemoval=false) public boolean isPermittedTypeForUpdate(ComposedType ct)
      Deprecated.
      Checks whether the given type is permitted by this header (is subtype of configured one and fits all checks of calculatePermittedType(ComposedType)) for updates in UPDATE or INSERT_UPDATE modes.
      Parameters:
      ct - type to check for permitted type
      Returns:
      true if given type is permitted by this header, false otherwise
    • isPermittedTypeForUpdate

      public boolean isPermittedTypeForUpdate(String ct)
      Checks whether the given type is permitted by this header (is subtype of configured one and fits all checks of calculatePermittedType(ComposedType)) for updates in UPDATE or INSERT_UPDATE modes.
      Parameters:
      ct - type to check for permitted type
      Returns:
      true if given type is permitted by this header, false otherwise
    • isPermittedType

      public boolean isPermittedType(String code)
      Checks whether the given type is permitted by this header (is subtype of configured one and fits all checks of calculatePermittedType(ComposedType)).
      Parameters:
      code - code of type to check for permitted type
      Returns:
      true if given type is permitted by this header, false otherwise
    • getMode

      public EnumerationValue getMode()
      Gets the mode of this header configured at header line.
      Returns:
      configured header mode
    • dump

      public Map<Integer,String> dump()
      Gets the header as list of Strings for dumping purposes.
      Returns:
      header as list of strings mapped to their position
    • addOmittedTypeMessage

      protected void addOmittedTypeMessage(PK typePK, String msg)
      Adds an message to the omitted type messages list. These messages are created if a type is found which fits the configured type but does not has passed all checks of the calculatePermittedType(ComposedType).
      Parameters:
      msg - message containing the omitted type code and reason why it was omitted
    • calculatePermittedType

      protected HeaderDescriptor.PermittedTypeMapping calculatePermittedType(ComposedType ct)
      Creates a HeaderDescriptor.PermittedTypeMapping for given composed type. While creation it checks that
      • it is not abstract and not jalo-only
      • at least one unique attribute column can be found in INSERT or INSERT_UPDATE mode
      • no mandatory attribute columns are missing except REMOVE mode
      • an no initial-only attribute columns are missing in INSERT or INSERT_UPDATE mode
      In ImpExConstants.Enumerations.ImpExValidationModeEnum.IMPORT_RELAXED mode all checks are disabled. If an check fails, a null will be returned and the addOmittedTypeMessage(PK, String) will be called.
      Parameters:
      ct - composed type for which a mapping will be created
      Returns:
      created type mapping with all columns enabled which are configured at header or null if an check fails
    • calculatePermittedTypes

      protected Map<String,HeaderDescriptor.PermittedTypeMapping> calculatePermittedTypes()
      Filters any composed (sub)type which doesn't fit the currently configured columns. A type is not permitted when:
      • it is abstract or jalo-only
      • no unique attribute columns can be found in INSERT or INSERT_UPDATE mode
      • mandatory attribute columns are missing except REMOVE mode
      • initial-only attribute columns are missing in INSERT or INSERT_UPDATE mode
      Returns:
      all permitted types based upon this headers composed type
    • validate

      public void validate() throws HeaderValidationException
      Specified by:
      validate in class AbstractDescriptor
      Throws:
      HeaderValidationException
    • getColumnsForUpdate

      @Deprecated(since="ages", forRemoval=false) public Set<StandardColumnDescriptor> getColumnsForUpdate(ComposedType targetType)
      Deprecated.
      since ages - usegetColumnsForUpdate(String) instead.
      Gets all permitted columns for given composed type which are not
      • read-only,
      • and inital-only
      • and unique columns.
      These columns has to be used for update case.
      Parameters:
      targetType - type for which the columns for update are needed
      Returns:
      set of columns for update or empty set if type is not permitted
    • getColumnsForUpdate

      public Set<StandardColumnDescriptor> getColumnsForUpdate(String targetTypeCode)
      Gets all permitted columns for given composed type's code which are not
      • read-only,
      • and inital-only
      • and unique columns.
      These columns has to be used for update case.
      Parameters:
      targetTypeCode - type code for which the columns for update are needed
      Returns:
      set of columns for update or empty set if type is not permitted
    • getColumnsForCreation

      @Deprecated(since="ages", forRemoval=false) public Set<StandardColumnDescriptor> getColumnsForCreation(ComposedType targetType)
      Deprecated.
      since ages - usegetColumnsForCreation(String) instead
      Gets all permitted columns for given composed type which are not
      • read-only
      • and part-of.
      These columns has to be used for creation case.
      Parameters:
      targetType - type for which the columns for creation are needed
      Returns:
      set of columns for creation or empty set if type is not permitted
    • getColumnsForCreation

      public Set<StandardColumnDescriptor> getColumnsForCreation(String targetTypeCode)
      Gets all permitted columns for given composed type's code which are not
      • read-only
      • and part-of.
      These columns has to be used for creation case.
      Parameters:
      targetTypeCode - type coce for which the columns for creation are needed
      Returns:
      set of columns for creation or empty set if type is not permitted
    • getPartOfColumns

      public Set<StandardColumnDescriptor> getPartOfColumns(ComposedType targetType)
      Gets all permitted columns for given composed type which are
      • part-of
      and not
      • read-only.
      Parameters:
      targetType - type for which the part-of columns are needed
      Returns:
      set of part-of columns or empty set if type is not permitted
    • getPartOfColumns

      public Set<StandardColumnDescriptor> getPartOfColumns(String targetTypeCode)
      Gets all permitted columns for given composed type's code which are
      • part-of
      and not
      • read-only.
      Parameters:
      targetTypeCode - type for which the part-of columns are needed
      Returns:
      set of part-of columns or empty set if type is not permitted
    • getAllColumns

      public Set<StandardColumnDescriptor> getAllColumns(ComposedType targetType)
      Gets all columns for given composed type.
      Parameters:
      targetType - type for which the all columns are needed
      Returns:
      set of columns or empty set if type is not permitted
    • getUniqueAttributeColumns

      public Set<StandardColumnDescriptor> getUniqueAttributeColumns(ComposedType targetType)
      Gets all columns for given composed type which are
      • unique.
      Parameters:
      targetType - type for which the unique columns are needed
      Returns:
      set of unique columns or empty set if type is not permitted
    • getUniqueAttributeColumns

      public Set<StandardColumnDescriptor> getUniqueAttributeColumns(String targetTypeCode)
      Gets all permitted columns for given composed type which are
      • unique.
      Parameters:
      targetTypeCode - code of type for which the unique columns are needed
      Returns:
      set of unique columns or empty set if type is not permitted
    • calculateUniqueAttributeColumns

      protected Set<StandardColumnDescriptor> calculateUniqueAttributeColumns(ComposedType targetType)
      Gets all columns configured at header which are describing an attribute of given type and are unique.
      Parameters:
      targetType - type to which all configured unique columns will be returned
      Returns:
      list of all unique columns in respect to given type
    • calculateUniqueAttributeColumns

      public Set<StandardColumnDescriptor> calculateUniqueAttributeColumns()
      Gets the configured columns which are describing attributes of the default composed type (see getDefaultComposedType()) and are unique.
      Returns:
      unique columns of default composed type
    • getAllColumnQualifiers

      public List<String> getAllColumnQualifiers()
      Gets a list of all configured columns represented by their qualifier.
      Returns:
      list of all configured columns
    • getColumnsByAttribute

      protected Collection<StandardColumnDescriptor> getColumnsByAttribute(AttributeDescriptor ad)
      Searches the set of configured columns for columns which are describing given type attribute (which are mapped to this descriptor).
      Parameters:
      ad - descriptor to which all configured columns are needed
      Returns:
      list of all columns which are matched to given descriptor or an empty list
    • getColumnsByQualifier

      public Collection<AbstractColumnDescriptor> getColumnsByQualifier(String qualifier)
      Searches the set of configured columns for columns with given qualifier.
      Parameters:
      qualifier - qualifier of resulting columns
      Returns:
      list of all columns which have given qualifier as qualifier
    • getLocation

      public String getLocation()
      Gets the location of this header line within the read ImpExScript.
      Returns:
      location of based header line
    • getDocumentIDRegistry

      public DocumentIDRegistry getDocumentIDRegistry()
      Returns the used registry for document id's.
      Returns:
      the used document id registry
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getOmittedTypesMessages

      public String getOmittedTypesMessages(PK typePK)
      Gets a reason text for not omitting given type for this header.
      Returns:
      reason text for omitting the type or null if there is no reason.
    • getInterceptorRelatedParameters

      public Map<String,Object> getInterceptorRelatedParameters()