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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanattributeContainsCmsComponents(AttributeDescriptorModel attributeDescriptorModel) Helper method to determine whether an attribute contains cms components.protected AttributeContainsCMSComponentsPredicateprotected <T> TgetAttributeValue(AttributeDescriptorModel attribute, ItemModel sourceModel) This method is used to get the value of the desired attribute in the provided source model.This method returns the transformation function to use to render CMS components.getCollectionGetter(AttributeDescriptorModel attribute, ItemModel sourceModel, Function<Object, Object> goDeeperOrSerialize) This function is used to retrieve aSupplierthat can be used to get the representation of a collection stored in an attribute.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.getLocalizedCollectionGetter(AttributeDescriptorModel attribute, ItemModel sourceModel, Function<Object, Object> goDeeperOrSerialize) This function is used to retrieve aSupplierthat can be used to get the representation of a localized collection value stored in an attribute.getLocalizedGetter(AttributeDescriptorModel attribute, ItemModel sourceModel, Function<Object, Object> goDeeperOrSerialize) This function is used to retrieve aSupplierthat can be used to get the representation of a localized value stored in an attribute.protected ModelServiceprotected RenderingVisibilityServiceprotected Converter<AbstractCMSComponentModel,String> getSimpleGetter(AttributeDescriptorModel attribute, ItemModel sourceModel, Function<Object, Object> goDeeperOrSerialize) This function is used to retrieve a Supplier that can be used to get the representation of the value of an attribute.protected booleanisElementEligibleForRendering(AttributeDescriptorModel attributeDescriptorModel, Object element) This method is used to determine if an element is allowed to be rendered.voidsetAttributeContainsCMSComponentsPredicate(AttributeContainsCMSComponentsPredicate attributeContainsCMSComponentsPredicate) voidsetCmsComponentModelToDataRenderingConverter(Converter<AbstractCMSComponentModel, AbstractCMSComponentData> cmsComponentModelToDataRenderingConverter) voidsetCollectionToRepresentationConverter(AttributeValueToRepresentationConverter<Collection<Object>, Collection<Object>> collectionToRepresentationConverter) voidsetModelService(ModelService modelService) voidsetRenderingCacheService(RenderingCacheService<AbstractCMSComponentData> renderingCacheService) voidsetRenderingVisibilityService(RenderingVisibilityService renderingVisibilityService) voidsetSimpleCmsComponentAttributeConverter(Converter<AbstractCMSComponentModel, String> simpleCmsComponentAttributeConverter)
-
Constructor Details
-
RenderingAttributeValueToRepresentationStrategy
public RenderingAttributeValueToRepresentationStrategy()
-
-
Method Details
-
getSimpleGetter
public Supplier<Object> getSimpleGetter(AttributeDescriptorModel attribute, ItemModel sourceModel, Function<Object, Object> goDeeperOrSerialize) Description copied from interface:AttributeValueToRepresentationStrategyThis 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:
getSimpleGetterin interfaceAttributeValueToRepresentationStrategy- 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:AttributeValueToRepresentationStrategyThis function is used to retrieve aSupplierthat 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:
getCollectionGetterin interfaceAttributeValueToRepresentationStrategy- 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:AttributeValueToRepresentationStrategyThis function is used to retrieve aSupplierthat 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:
getLocalizedGetterin interfaceAttributeValueToRepresentationStrategy- 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:AttributeValueToRepresentationStrategyThis function is used to retrieve aSupplierthat 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:
getLocalizedCollectionGetterin interfaceAttributeValueToRepresentationStrategy- 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
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
This method returns the transformation function to use to render CMS components. The payload of the component is retrieved from the cache ifRenderingCacheServiceis 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
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 modelsourceModel- The model where to retrieve the value from.- Returns:
- The value of the attribute in the provided source model.
-
getModelService
-
setModelService
-
getAttributeContainsCMSComponentsPredicate
-
setAttributeContainsCMSComponentsPredicate
public void setAttributeContainsCMSComponentsPredicate(AttributeContainsCMSComponentsPredicate attributeContainsCMSComponentsPredicate) -
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
-
setRenderingVisibilityService
-
getCmsComponentModelToDataRenderingConverter
protected Converter<AbstractCMSComponentModel,AbstractCMSComponentData> getCmsComponentModelToDataRenderingConverter() -
setCmsComponentModelToDataRenderingConverter
public void setCmsComponentModelToDataRenderingConverter(Converter<AbstractCMSComponentModel, AbstractCMSComponentData> cmsComponentModelToDataRenderingConverter) -
getRenderingCacheService
-
setRenderingCacheService
public void setRenderingCacheService(RenderingCacheService<AbstractCMSComponentData> renderingCacheService)
-