Class RenderingAttributeValueToRepresentationStrategy

java.lang.Object
de.hybris.platform.cmsfacades.rendering.strategies.RenderingAttributeValueToRepresentationStrategy
All Implemented Interfaces:
AttributeValueToRepresentationStrategy

public class RenderingAttributeValueToRepresentationStrategy extends Object implements AttributeValueToRepresentationStrategy
This class is used by the DefaultCMSItemConverter to convert items into a representation suited for rendering purposes. The transformation strategy is be based on the following rules: - Simple Value: -> If it's a Cms Component it needs to be converted into an AbstractCMSComponentData (through the cmsComponentModelToDataRenderingConverter) -> Otherwise, use the default transformation function. - Collection: -> If the collection contains Cms Components, get simple representation (uid). -> Otherwise, use the default transformation function for each item. - Localized Value: -> Get value for current language, and use same approach as Simple Value. - Localized Collection: -> For each element, do the same as Localized Value.
  • Constructor Details

    • RenderingAttributeValueToRepresentationStrategy

      public RenderingAttributeValueToRepresentationStrategy()
  • Method Details

    • getSimpleGetter

      public Supplier<Object> getSimpleGetter(AttributeDescriptorModel attribute, ItemModel sourceModel, Function<Object,Object> goDeeperOrSerialize)
      Description copied from interface: AttributeValueToRepresentationStrategy
      This function is used to retrieve a Supplier that can be used to get the representation of the value of an attribute. This representation is generated by applying the provided transformation function.
      Specified by:
      getSimpleGetter in interface AttributeValueToRepresentationStrategy
      Parameters:
      attribute - The object describing the attribute whose value will be transformed.
      sourceModel - The model containing the value that will be transformed.
      goDeeperOrSerialize - The function that will be used to transform the value into the expected object.
      Returns:
      A Supplier. Use get() to retrieve the transformed object.
    • getCollectionGetter

      public Supplier<Object> getCollectionGetter(AttributeDescriptorModel attribute, ItemModel sourceModel, Function<Object,Object> goDeeperOrSerialize)
      Description copied from interface: AttributeValueToRepresentationStrategy
      This function is used to retrieve a Supplier that can be used to get the representation of a collection stored in an attribute. This representation is generated by leveraging the provided transformation function.
      Specified by:
      getCollectionGetter in interface AttributeValueToRepresentationStrategy
      Parameters:
      attribute - The object describing the attribute whose value will be transformed.
      sourceModel - The model containing the collection that will be transformed.
      goDeeperOrSerialize - The function that will be used to transform the collection into the expected representation.
      Returns:
      A Supplier. Use get() to retrieve the transformed collection.
    • getLocalizedGetter

      public Supplier<Object> getLocalizedGetter(AttributeDescriptorModel attribute, ItemModel sourceModel, Function<Object,Object> goDeeperOrSerialize)
      Description copied from interface: AttributeValueToRepresentationStrategy
      This function is used to retrieve a Supplier that can be used to get the representation of a localized value stored in an attribute. This representation is generated by leveraging the provided transformation function.
      Specified by:
      getLocalizedGetter in interface AttributeValueToRepresentationStrategy
      Parameters:
      attribute - The object describing the attribute whose value will be transformed.
      sourceModel - The model containing the localized value that will be transformed.
      goDeeperOrSerialize - The function that will be used to transform the localized value into the expected representation.
      Returns:
      A Supplier. Use get() to retrieve the transformed localized value.
    • getLocalizedCollectionGetter

      public Supplier<Object> getLocalizedCollectionGetter(AttributeDescriptorModel attribute, ItemModel sourceModel, Function<Object,Object> goDeeperOrSerialize)
      Description copied from interface: AttributeValueToRepresentationStrategy
      This function is used to retrieve a Supplier that can be used to get the representation of a localized collection value stored in an attribute. This representation is generated by leveraging the provided transformation function.
      Specified by:
      getLocalizedCollectionGetter in interface AttributeValueToRepresentationStrategy
      Parameters:
      attribute - The object describing the attribute whose value will be transformed.
      sourceModel - The model containing the localized collection value that will be transformed.
      goDeeperOrSerialize - The function that will be used to transform the localized collection value into the expected representation.
      Returns:
      A Supplier. Use get() to retrieve the transformed localized collection value.
    • attributeContainsCmsComponents

      protected boolean attributeContainsCmsComponents(AttributeDescriptorModel attributeDescriptorModel)
      Helper method to determine whether an attribute contains cms components.
      Parameters:
      attributeDescriptorModel - The attribute to analyze.
      Returns:
      True if the attribute contains cms components, false otherwise.
    • getCmsComponentRenderingDataTransformationFunction

      protected Function<Object,Object> getCmsComponentRenderingDataTransformationFunction()
      This method returns the transformation function to use to render CMS components. The payload of the component is retrieved from the cache if RenderingCacheService is enabled.
      Returns:
      The transformation function to use for CMS components.
    • getElementToRenderingDataTransformationFunction

      protected Function<Object,Object> getElementToRenderingDataTransformationFunction(AttributeDescriptorModel attributeDescriptorModel, Function<Object,Object> defaultTransformationFunction)
      This method receives a transformation function, and wraps it in a new function that contains necessary logic for rendering purposes.
      Parameters:
      attributeDescriptorModel - The model that describes the attribute whose element(s) will be transformed with the provided transformation function.
      defaultTransformationFunction - The default function used to transform element(s) in the provided attribute.
      Returns:
      The new function that contains the extra logic needed for rendering purposes.
    • isElementEligibleForRendering

      protected boolean isElementEligibleForRendering(AttributeDescriptorModel attributeDescriptorModel, Object element)
      This method is used to determine if an element is allowed to be rendered. - If the element is not a component, it's always allowed. - If it's a component, it must be explicitly allowed (visible and no restrictions in effect).
      Parameters:
      attributeDescriptorModel - The model describing the attribute to analyze.
      element - The item to analyze.
      Returns:
      true if the element is allowed to be rendered. False otherwise.
    • getAttributeValue

      protected <T> T getAttributeValue(AttributeDescriptorModel attribute, ItemModel sourceModel)
      This method is used to get the value of the desired attribute in the provided source model.
      Type Parameters:
      T - The type of the returned value.
      Parameters:
      attribute - The attribute to retrieve from the model
      sourceModel - The model where to retrieve the value from.
      Returns:
      The value of the attribute in the provided source model.
    • getModelService

      protected ModelService getModelService()
    • setModelService

      public void setModelService(ModelService modelService)
    • getAttributeContainsCMSComponentsPredicate

      protected AttributeContainsCMSComponentsPredicate getAttributeContainsCMSComponentsPredicate()
    • setAttributeContainsCMSComponentsPredicate

      public void setAttributeContainsCMSComponentsPredicate(AttributeContainsCMSComponentsPredicate attributeContainsCMSComponentsPredicate)
    • getSimpleCmsComponentAttributeConverter

      protected Converter<AbstractCMSComponentModel,String> getSimpleCmsComponentAttributeConverter()
    • setSimpleCmsComponentAttributeConverter

      public void setSimpleCmsComponentAttributeConverter(Converter<AbstractCMSComponentModel,String> simpleCmsComponentAttributeConverter)
    • getCollectionToRepresentationConverter

      protected AttributeValueToRepresentationConverter<Collection<Object>,Collection<Object>> getCollectionToRepresentationConverter()
    • setCollectionToRepresentationConverter

      public void setCollectionToRepresentationConverter(AttributeValueToRepresentationConverter<Collection<Object>,Collection<Object>> collectionToRepresentationConverter)
    • getRenderingVisibilityService

      protected RenderingVisibilityService getRenderingVisibilityService()
    • setRenderingVisibilityService

      public void setRenderingVisibilityService(RenderingVisibilityService renderingVisibilityService)
    • getCmsComponentModelToDataRenderingConverter

      protected Converter<AbstractCMSComponentModel,AbstractCMSComponentData> getCmsComponentModelToDataRenderingConverter()
    • setCmsComponentModelToDataRenderingConverter

      public void setCmsComponentModelToDataRenderingConverter(Converter<AbstractCMSComponentModel,AbstractCMSComponentData> cmsComponentModelToDataRenderingConverter)
    • getRenderingCacheService

      public RenderingCacheService<AbstractCMSComponentData> getRenderingCacheService()
    • setRenderingCacheService

      public void setRenderingCacheService(RenderingCacheService<AbstractCMSComponentData> renderingCacheService)