Class DefaultCMSItemConverter

java.lang.Object
de.hybris.platform.cmsfacades.cmsitems.converter.DefaultCMSItemConverter
All Implemented Interfaces:
CMSItemConverter

public class DefaultCMSItemConverter extends Object implements CMSItemConverter
The CMSItemConverter is the first layer of converters applied to convert a given CMSItemModel into Map<String, Object>. The reason why this class accepts any kind of ItemModel is that this same converter will be reused recursively when attributes are part of (AttributeDescriptorModel.getPartOf()) the enclosing item model, hence denoting a composition. This converter is also handling localized attributes and collections.
  • Constructor Details

    • DefaultCMSItemConverter

      public DefaultCMSItemConverter()
  • Method Details

    • convert

      public Map<String,Object> convert(ItemModel source)
      Description copied from interface: CMSItemConverter
      Converts an ItemModel to a serializable Map.
      Specified by:
      convert in interface CMSItemConverter
      Parameters:
      source - the ItemModel to convert.
      Returns:
      the ItemModel converted to a Map
    • convert

      public ItemModel convert(Map<String,Object> map)
      Description copied from interface: CMSItemConverter
      Converts a deserializable Map to an ItemModel.
      Specified by:
      convert in interface CMSItemConverter
      Parameters:
      map - the Map<String, Object> to convert
      Returns:
      the Map converted to an ItemModel
    • convertAndValidate

      protected ItemModel convertAndValidate(Map<String,Object> map, ComposedTypeModel composedType)
      Converts and validates a deserializable Map to an ItemModel.
      Parameters:
      map - the Map<String, Object> to convert
      composedType - the type to which the Map will be converted to.
      Returns:
      the Map converted to an ItemModel
    • convertAndValidateAttribute

      protected void convertAndValidateAttribute(Map<String,Object> map, ItemModel itemModel, AttributeDescriptorModel attribute)
      Converts and validates a primitive data or deserializable Map to an attribute value (primitive or ItemModel).
      Parameters:
      map - the Map<String, Object> containing the attribute data to convert
      itemModel - the model which attribute value will be updated
      attribute - the attribute descriptor providing information about the attribute to be updated
    • initializeCloneComponentAttributeContext

      protected boolean initializeCloneComponentAttributeContext(String qualifier, Object targetValue)
      Check that the value for the given qualifier was modified during the cloning process and stores the source component attribute value in the clone component context in the session.
      Parameters:
      qualifier - the attribute field name
      targetValue - the value to be applied to the component model
      Returns:
      TRUE when the attribute value was modified during the component cloning flow;
      FALSE when the given qualifier is UID or when the attribute value was not modified
    • getCmsItemValidator

      protected CMSItemValidator<ItemModel> getCmsItemValidator(Map<String,Object> map)
    • getItemModelFromRepresentation

      protected ItemModel getItemModelFromRepresentation(Map<String,Object> map)
      Get Item Model from request payload
      Parameters:
      map - the map representing the Item Model
      Returns:
      the ItemModel related to this Map representation
    • isCloneComponentFlow

      protected boolean isCloneComponentFlow(Map<String,Object> map)
      Determine if a map that represents the item model is a component clone
      Parameters:
      map - the map representing the Item Model
      Returns:
      a boolean that determines if the item being created is a component clone
    • getCloneModelFromRepresentation

      protected ItemModel getCloneModelFromRepresentation(String sourceComponentUuid)
      Create a Clone Item Model and saves it to the CloneComponentContextProvider or get a Clone Item Model from the CloneComponentContextProvider
      Parameters:
      sourceComponentUuid - the UUID representing the source Item Model to clone from
      Returns:
      the ItemModel cloned from the provided sourceComponentUuid
    • transformCollection

      protected Collection<Object> transformCollection(AttributeDescriptorModel attribute, Collection<Object> collection, Function<Object,Object> transform)
      Convenience method to apply a transformation to all elements of a Function
      Parameters:
      collection - the Collection the elements of which we need to transform
      transform - the transformation Function that will be applied on each element of the collection
      Returns:
      a new collection
    • addTransformedCollection

      protected void addTransformedCollection(AttributeDescriptorModel attribute, Function<Object,Object> transform, AtomicInteger counter, Collection<Object> transformedCollection, Object value)
    • transformLocalizedValue

      protected Map<String,Object> transformLocalizedValue(AttributeDescriptorModel attribute, Map<String,Object> itemMap, ItemModel itemModel, Function<Object,Object> transform)
      Convenience method to apply a transformation to values of a Map
      Parameters:
      itemMap - the Map the values of which we need to transform
      itemModel - the model containing the original attribute value. If this is a new model, the attribute value will be empty.
      transform - the transformation Function that will be applied on each values of the itemMap
      Returns:
      a new itemMap
    • buildTransformValue

      protected Object buildTransformValue(AttributeDescriptorModel attribute, Function<Object,Object> transform, String language, Object value)
    • leafOrDeeperConvertToRepresentation

      protected Function<Object,Object> leafOrDeeperConvertToRepresentation(AttributeDescriptorModel attribute)
      Given an AttributeDescriptorModel, will return a Function that will do the following:
      if the attribute is a partOf of the owning type, it will return a conversion of it by means of convert(ItemModel)
      if the attribute is not a partOf of the owning type, it will return a conversion of it by means of the appropriate model-to-data converter returned by the attributeStrategyConverter.
      Parameters:
      attribute - the AttributeDescriptorModel describing the metadata of the property of a class
      Returns:
      a conversion of type Object
    • leafOrDeeperConvertToModel

      protected Function<Object,Object> leafOrDeeperConvertToModel(AttributeDescriptorModel attribute)
      Given an AttributeDescriptorModel, will return a Function that will do the following:
      if the attribute is a partOf of the owning type, it will return a conversion of it by means of convert(Map<String, Object>)
      if the attribute is not a partOf of the owning type, it will return a conversion of it by means of the appropriate data-to-model converter returned by the attributeStrategyConverter. if no converter is found, AttributeContentConverter.Value.NOT_TO_BE_SET is returned to instruct no to try to persist this property
      Parameters:
      attribute - the AttributeDescriptorModel describing the metadata of the property of a class
      Returns:
      a conversion of type Object
      Throws:
      IllegalAccessException
      InstantiationException
    • buildAttributeContentConverter

      protected Object buildAttributeContentConverter(AttributeDescriptorModel attribute, Object value)
    • isDynamicAttribute

      protected boolean isDynamicAttribute(AttributeDescriptorModel attribute)
      Returns true if the attribute is a dynamic attribute. Note that this method doesn't consider RelationDescriptorModels as dynamic.
      Parameters:
      attribute - The attribute to evaluate.
      Returns:
      true if the attribute is dynamic, false otherwise.
    • getAttributes

      protected List<AttributeDescriptorModel> getAttributes(ComposedTypeModel composedType)
      Returns the list of all attributes defined for a given composed type, including the inherited ones.
      Parameters:
      composedType - the composedType the attributes belong to
      Returns:
      a list of all attributes declared, including inherited attributes.
    • getAttributeValues

      protected Function<ItemModel,Map<AttributeDescriptorModel,Object>> getAttributeValues()
      Function to get a Map of attribute descriptors and its Object value for a given ItemModel
      Returns:
      a function that when executed returns a map with attributes and their respective values.
    • convertAttributeValueToRepresentation

      protected Function<AttributeDescriptorModel,Optional<Object>> convertAttributeValueToRepresentation(ItemModel source)
      Function that returns the serializable representation value (String, Map or Collection) of all AttributeDescriptorModel of a given ItemModel source. This methods recursively handles the following cases and their possible combinations:
      • localized field
      • collections
      • partOf
      Parameters:
      source - the ItemModel owning all the AttributeDescriptorModel
      Returns:
      returns the serializable representations
    • convertRepresentationToAttributeValue

      protected Function<AttributeDescriptorModel,Optional<Object>> convertRepresentationToAttributeValue(Object source, ItemModel itemModel)
      Function that constructs the persistable representation of all AttributeDescriptorModel of a given serializable source (String, Map or Collection). This methods recursively handles the following cases and their possible combinations:
      • localized field
      • collections
      • partOf
      Parameters:
      source - serializable source (String, Map or Collection) described by a AttributeDescriptorModel
      itemModel - the model containing the original attribute value. If this is a new model, the attribute value will be empty.
      Returns:
      returns the persistable representations
    • getAttributeValue

      protected Function<AttributeDescriptorModel,Optional<Object>> getAttributeValue(Supplier<Object> localizedCollectionGetter, Supplier<Object> localizedGetter, Supplier<Object> collectionGetter, Supplier<Object> simpleGetter)
      Returns a Function aimed at converting any value described by a AttributeDescriptorModel. This function will execute one of the provided suppliers depending on whether the attribute is localized and/or a collection
      Parameters:
      localizedCollectionGetter - a Supplier invoked if the attribute is both localized and a collection
      localizedGetter - a Supplier invoked if the attribute is localized and not a collection
      collectionGetter - a Supplier invoked if the attribute is a collection and not localized
      simpleGetter - a Supplier invoked if the attribute is neither localized nor an attribute
      Returns:
      a Function to convert a value
    • validate

      protected void validate(Object value, AttributeDescriptorModel attribute, AttributeContentValidator validator)
      Validates and throws an exception if there are validation errors
      Parameters:
      value - the value being validated
      attribute - the attribute descriptor model
      validator - the validator to be used
    • collectValidationErrors

      protected void collectValidationErrors(ValidationException e, Optional<String> language, Optional<Integer> position)
      Collects the errors in the validation exception and adds to the global validation context.
      Parameters:
      e - the exception
      language - optional; the validated language
      position - optional; the position in which the object value in the collection
    • modelHasAssignedUUID

      protected boolean modelHasAssignedUUID(Map<String,Object> valueMap)
    • buildAttributeValue

      protected Optional<Object> buildAttributeValue(Object source, ItemModel itemModel, AttributeDescriptorModel attribute)
    • buildConversionExceptionForSimpleGetter

      protected void buildConversionExceptionForSimpleGetter(Object source, AttributeDescriptorModel attribute, ConversionException e)
    • principalCanUpdateAttribute

      protected boolean principalCanUpdateAttribute(String typeCode, String qualifier)
      This method determines whether the current principal can update the attribute identified by the qualifier in the enclosing type. A user can update an attribute when both read and change attribute permissions are granted.
      Parameters:
      typeCode - the item model type code
      qualifier - the attribute qualifier
      Returns:
      TRUE when the user has read and change permissions on the attribute; otherwise FALSE
    • principalCanWriteAttributeLanguage

      protected boolean principalCanWriteAttributeLanguage(String qualifier, String languageIsoCode, Set<String> writeableLanguages)
      This method is used to check if the current principal can write a language of a localized attribute.
      Parameters:
      qualifier - - the qualifier of the attribute whose language wants to be changed.
      languageIsoCode - - the ISO code of the language that wants to be updated.
      writeableLanguages - - the list of languages the current principal can write. Each element represents the ISO code of a language
      Returns:
      a boolean flag. True, if the user can write the language for the localized element; False, otherwise.
    • convertRepresentationToAttributeValue

      @Deprecated(since="1811", forRemoval=true) protected Function<AttributeDescriptorModel,Optional<Object>> convertRepresentationToAttributeValue(Object source)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Function that constructs the persistable representation of all AttributeDescriptorModel of a given serializable source (String, Map or Collection). This methods recursively handles the following cases and their possible combinations:
      • localized field
      • collections
      • partOf
      Parameters:
      source - serializable source (String, Map or Collection) described by a AttributeDescriptorModel
      Returns:
      returns the persistable representations
    • transformLocalizedValue

      @Deprecated(since="1811", forRemoval=true) protected Map<String,Object> transformLocalizedValue(AttributeDescriptorModel attribute, Map<String,Object> itemMap, Function<Object,Object> transform)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Convenience method to apply a transformation to values of a Map
      Parameters:
      itemMap - the Map the values of which we need to transform
      transform - the transformation Function that will be applied on each values of the itemMap
      Returns:
      a new itemMap
    • getTypeService

      protected TypeService getTypeService()
    • setTypeService

      public void setTypeService(TypeService typeService)
    • getModelService

      protected ModelService getModelService()
    • setModelService

      public void setModelService(ModelService modelService)
    • getLocalizedPopulator

      protected LocalizedPopulator getLocalizedPopulator()
    • setLocalizedPopulator

      public void setLocalizedPopulator(LocalizedPopulator localizedPopulator)
    • getAttributeStrategyConverter

      public AttributeStrategyConverterProvider getAttributeStrategyConverter()
    • setAttributeStrategyConverter

      public void setAttributeStrategyConverter(AttributeStrategyConverterProvider attributeStrategyConverter)
    • getUniqueItemIdentifierService

      protected UniqueItemIdentifierService getUniqueItemIdentifierService()
    • setUniqueItemIdentifierService

      public void setUniqueItemIdentifierService(UniqueItemIdentifierService uniqueItemIdentifierService)
    • getCmsAdminItemService

      protected CMSAdminItemService getCmsAdminItemService()
    • setCmsAdminItemService

      public void setCmsAdminItemService(CMSAdminItemService cmsAdminItemService)
    • getBaseAttributeContentValidator

      protected AttributeContentValidator getBaseAttributeContentValidator()
    • setBaseAttributeContentValidator

      public void setBaseAttributeContentValidator(AttributeContentValidator baseAttributeContentValidator)
    • getExtendedAttributeContentValidator

      protected AttributeContentValidator getExtendedAttributeContentValidator()
    • setExtendedAttributeContentValidator

      public void setExtendedAttributeContentValidator(AttributeContentValidator extendedAttributeContentValidator)
    • getValidationErrorsProvider

      protected ValidationErrorsProvider getValidationErrorsProvider()
    • setValidationErrorsProvider

      public void setValidationErrorsProvider(ValidationErrorsProvider validationErrorsProvider)
    • getNestedOrPartOfAttributePredicate

      public NestedOrPartOfAttributePredicate getNestedOrPartOfAttributePredicate()
    • setNestedOrPartOfAttributePredicate

      public void setNestedOrPartOfAttributePredicate(NestedOrPartOfAttributePredicate nestedOrPartOfAttributePredicate)
    • getValidatableService

      public ValidatableService getValidatableService()
    • setValidatableService

      public void setValidatableService(ValidatableService validatableService)
    • getCmsItemValidatorCreate

      public CMSItemValidator<ItemModel> getCmsItemValidatorCreate()
    • setCmsItemValidatorCreate

      public void setCmsItemValidatorCreate(CMSItemValidator<ItemModel> cmsItemValidatorCreate)
    • getCmsItemValidatorUpdate

      public CMSItemValidator<ItemModel> getCmsItemValidatorUpdate()
    • setCmsItemValidatorUpdate

      public void setCmsItemValidatorUpdate(CMSItemValidator<ItemModel> cmsItemValidatorUpdate)
    • getOriginalClonedItemProvider

      protected OriginalClonedItemProvider<ItemModel> getOriginalClonedItemProvider()
    • setOriginalClonedItemProvider

      public void setOriginalClonedItemProvider(OriginalClonedItemProvider<ItemModel> originalClonedItemProvider)
    • getComponentCloningStrategy

      protected ComponentCloningStrategy getComponentCloningStrategy()
    • setComponentCloningStrategy

      public void setComponentCloningStrategy(ComponentCloningStrategy componentCloningStrategy)
    • getCloneComponentContextProvider

      protected CloneComponentContextProvider getCloneComponentContextProvider()
    • setCloneComponentContextProvider

      public void setCloneComponentContextProvider(CloneComponentContextProvider cloneComponentContextProvider)
    • getCloneAttributeStrategyConverter

      protected AttributeStrategyConverterProvider getCloneAttributeStrategyConverter()
    • setCloneAttributeStrategyConverter

      public void setCloneAttributeStrategyConverter(AttributeStrategyConverterProvider cloneAttributeStrategyConverter)
    • getAttributeValueToRepresentationStrategy

      protected AttributeValueToRepresentationStrategy getAttributeValueToRepresentationStrategy()
    • setAttributeValueToRepresentationStrategy

      public void setAttributeValueToRepresentationStrategy(AttributeValueToRepresentationStrategy attributeValueToRepresentationStrategy)
    • getComposedTypeToAttributeCollectionConverter

      protected ComposedTypeToAttributeCollectionConverter getComposedTypeToAttributeCollectionConverter()
    • setComposedTypeToAttributeCollectionConverter

      public void setComposedTypeToAttributeCollectionConverter(ComposedTypeToAttributeCollectionConverter composedTypeToAttributeCollectionConverter)
    • getCustomPopulators

      protected List<Populator<ItemModel,Map<String,Object>>> getCustomPopulators()
    • setCustomPopulators

      public void setCustomPopulators(List<Populator<ItemModel,Map<String,Object>>> customPopulators)
    • getPermissionCRUDService

      protected PermissionCRUDService getPermissionCRUDService()
    • setPermissionCRUDService

      public void setPermissionCRUDService(PermissionCRUDService permissionCRUDService)
    • getCmsUserService

      protected CMSUserService getCmsUserService()
    • setCmsUserService

      public void setCmsUserService(CMSUserService cmsUserService)
    • getCmsPermissionChecker

      protected CMSPermissionChecker getCmsPermissionChecker()
    • setCmsPermissionChecker

      public void setCmsPermissionChecker(CMSPermissionChecker cmsPermissionChecker)
    • getIsCollectionPredicate

      protected Predicate<AttributeDescriptorModel> getIsCollectionPredicate()
    • setIsCollectionPredicate

      public void setIsCollectionPredicate(Predicate<AttributeDescriptorModel> isCollectionPredicate)
    • getOriginalConvertedItemProvider

      protected CMSItemContextProvider<Map<String,Object>> getOriginalConvertedItemProvider()
    • setOriginalConvertedItemProvider

      public void setOriginalConvertedItemProvider(CMSItemContextProvider<Map<String,Object>> originalConvertedItemProvider)
    • getCmsItemAttributeFilterEnablerService

      public CMSItemAttributeFilterEnablerService getCmsItemAttributeFilterEnablerService()
    • setCmsItemAttributeFilterEnablerService

      public void setCmsItemAttributeFilterEnablerService(CMSItemAttributeFilterEnablerService cmsItemAttributeFilterEnablerService)