Class RenderingAttributeValueToRepresentationStrategy
- java.lang.Object
-
- de.hybris.platform.cmsfacades.rendering.strategies.RenderingAttributeValueToRepresentationStrategy
-
- All Implemented Interfaces:
AttributeValueToRepresentationStrategy
public class RenderingAttributeValueToRepresentationStrategy extends java.lang.Object implements AttributeValueToRepresentationStrategy
This class is used by theDefaultCMSItemConverterto 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 Constructor Description RenderingAttributeValueToRepresentationStrategy()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleanattributeContainsCmsComponents(AttributeDescriptorModel attributeDescriptorModel)Helper method to determine whether an attribute contains cms components.protected AttributeContainsCMSComponentsPredicategetAttributeContainsCMSComponentsPredicate()protected <T> TgetAttributeValue(AttributeDescriptorModel attribute, ItemModel sourceModel)This method is used to get the value of the desired attribute in the provided source model.protected Converter<AbstractCMSComponentModel,AbstractCMSComponentData>getCmsComponentModelToDataRenderingConverter()protected java.util.function.Function<java.lang.Object,java.lang.Object>getCmsComponentRenderingDataTransformationFunction()This method returns the transformation function to use to render CMS components.java.util.function.Supplier<java.lang.Object>getCollectionGetter(AttributeDescriptorModel attribute, ItemModel sourceModel, java.util.function.Function<java.lang.Object,java.lang.Object> goDeeperOrSerialize)This function is used to retrieve aSupplierthat can be used to get the representation of a collection stored in an attribute.protected AttributeValueToRepresentationConverter<java.util.Collection<java.lang.Object>,java.util.Collection<java.lang.Object>>getCollectionToRepresentationConverter()protected java.util.function.Function<java.lang.Object,java.lang.Object>getElementToRenderingDataTransformationFunction(AttributeDescriptorModel attributeDescriptorModel, java.util.function.Function<java.lang.Object,java.lang.Object> defaultTransformationFunction)This method receives a transformation function, and wraps it in a new function that contains necessary logic for rendering purposes.java.util.function.Supplier<java.lang.Object>getLocalizedCollectionGetter(AttributeDescriptorModel attribute, ItemModel sourceModel, java.util.function.Function<java.lang.Object,java.lang.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.java.util.function.Supplier<java.lang.Object>getLocalizedGetter(AttributeDescriptorModel attribute, ItemModel sourceModel, java.util.function.Function<java.lang.Object,java.lang.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 ModelServicegetModelService()protected RenderingVisibilityServicegetRenderingVisibilityService()protected Converter<AbstractCMSComponentModel,java.lang.String>getSimpleCmsComponentAttributeConverter()java.util.function.Supplier<java.lang.Object>getSimpleGetter(AttributeDescriptorModel attribute, ItemModel sourceModel, java.util.function.Function<java.lang.Object,java.lang.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, java.lang.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<java.util.Collection<java.lang.Object>,java.util.Collection<java.lang.Object>> collectionToRepresentationConverter)voidsetModelService(ModelService modelService)voidsetRenderingVisibilityService(RenderingVisibilityService renderingVisibilityService)voidsetSimpleCmsComponentAttributeConverter(Converter<AbstractCMSComponentModel,java.lang.String> simpleCmsComponentAttributeConverter)
-
-
-
Method Detail
-
getSimpleGetter
public java.util.function.Supplier<java.lang.Object> getSimpleGetter(AttributeDescriptorModel attribute, ItemModel sourceModel, java.util.function.Function<java.lang.Object,java.lang.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 java.util.function.Supplier<java.lang.Object> getCollectionGetter(AttributeDescriptorModel attribute, ItemModel sourceModel, java.util.function.Function<java.lang.Object,java.lang.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 java.util.function.Supplier<java.lang.Object> getLocalizedGetter(AttributeDescriptorModel attribute, ItemModel sourceModel, java.util.function.Function<java.lang.Object,java.lang.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 java.util.function.Supplier<java.lang.Object> getLocalizedCollectionGetter(AttributeDescriptorModel attribute, ItemModel sourceModel, java.util.function.Function<java.lang.Object,java.lang.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
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 java.util.function.Function<java.lang.Object,java.lang.Object> getCmsComponentRenderingDataTransformationFunction()
This method returns the transformation function to use to render CMS components.- Returns:
- The transformation function to use for CMS components.
-
getElementToRenderingDataTransformationFunction
protected java.util.function.Function<java.lang.Object,java.lang.Object> getElementToRenderingDataTransformationFunction(AttributeDescriptorModel attributeDescriptorModel, java.util.function.Function<java.lang.Object,java.lang.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, java.lang.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 modelsourceModel- 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,java.lang.String> getSimpleCmsComponentAttributeConverter()
-
setSimpleCmsComponentAttributeConverter
public void setSimpleCmsComponentAttributeConverter(Converter<AbstractCMSComponentModel,java.lang.String> simpleCmsComponentAttributeConverter)
-
getCollectionToRepresentationConverter
protected AttributeValueToRepresentationConverter<java.util.Collection<java.lang.Object>,java.util.Collection<java.lang.Object>> getCollectionToRepresentationConverter()
-
setCollectionToRepresentationConverter
public void setCollectionToRepresentationConverter(AttributeValueToRepresentationConverter<java.util.Collection<java.lang.Object>,java.util.Collection<java.lang.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)
-
-