Class DefaultCMSVersionToDataConverter
- java.lang.Object
-
- de.hybris.platform.cms2.version.converter.impl.DefaultCMSVersionToDataConverter
-
-
Constructor Summary
Constructors Constructor Description DefaultCMSVersionToDataConverter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected VersionAttributeDescriptorbuildVersionAttributeDescriptor(TypeModel typeModel, AttributeDescriptorModel attribute)java.lang.Stringconvert(ItemModel itemModel)Uses the sourceSobject and produces an new instance ofT.protected java.lang.ObjectconvertAttributeValue(VersionAttributeDescriptor attribute, java.lang.Object attributeValue)Converts an attribute value to a format supported byPayloadSerializer.protected java.util.Collection<java.lang.Object>convertCollection(VersionAttributeDescriptor versionAttributeDescriptor, java.util.Collection<java.lang.Object> collection)Converts collection ofObjectelements.protected java.util.Map<LanguageModel,java.lang.Object>convertLocalizedValue(ItemModel itemModel, AttributeDescriptorModel attribute, java.util.function.Function<java.lang.Object,java.lang.Object> converter)Converts the localized attribute value.protected java.util.function.Function<AttributeDescriptorModel,java.util.Optional<java.lang.Object>>getAttributeRelatedData(java.util.function.Supplier<java.lang.Object> localizedCollectionGetter, java.util.function.Supplier<java.lang.Object> localizedGetter, java.util.function.Supplier<java.lang.Object> collectionGetter, java.util.function.Supplier<java.lang.Object> simpleGetter)Returns aFunctionaimed at converting any value described by aAttributeDescriptorModel.protected java.util.Optional<java.lang.Object>getAttributeValueFromItem(ItemModel itemModel, AttributeDescriptorModel attribute)Extracts the value from itemModel based on attribute qualifier.protected java.util.Optional<java.lang.Object>getAttributeValueFromItem(ItemModel itemModel, AttributeDescriptorModel attribute, java.util.Locale locale)Extracts the value from itemModel based on attribute qualifier and locale.protected java.util.function.Function<AttributeDescriptorModel,java.util.Optional<java.lang.Object>>getAttributeValueMapperForItem(ItemModel itemModel)Returns a function that acceptsAttributeDescriptorModeland converts attribute value to a format supported byPayloadSerializer.protected CMSVersionHelpergetCmsVersionHelper()protected CollectionHelpergetCollectionHelper()protected CommonI18NServicegetCommonI18NService()protected java.util.Map<java.lang.String,java.lang.Object>getConvertedAttributeValues(ItemModel itemModel)Returns converted values forItemModelattributes.protected AttributeStrategyConverterProvider<VersionAttributeDescriptor>getConverterProvider()protected java.util.Map<java.lang.String,java.lang.Object>getCustomConvertedAttributeValues(ItemModel itemModel)Returns converted values for custom attributes.protected CustomAttributeStrategyConverterProvidergetCustomConverterProvider()protected java.util.function.Predicate<AttributeDescriptorModel>getIsCollectionPredicate()protected java.util.Map<LanguageModel,java.lang.Object>getMapOfLanguages(ItemModel itemModel, AttributeDescriptorModel attribute)Method generates theMapof theLanguageModeland theObjectthat represents the value for the language.protected ModelServicegetModelService()protected PayloadSerializergetPayloadSerializer()protected VersionAttributeDescriptorgetVersionAttribute(AttributeDescriptorModel attribute)ReturnsVersionAttributeDescriptorbased onAttributeDescriptorModel.protected LocalizedAttributesListprepareLocalizedValueForSerialization(AttributeDescriptorModel attribute, java.util.Map<LanguageModel,java.lang.Object> localizedValues)Packs the converted localized value inside a class supported byPayloadSerializer.protected SLDDataContainer.AttributeValueprepareSimpleValueForSerialization(AttributeDescriptorModel attribute, java.lang.Object convertedValue)Packs the converted value inside a class supported byPayloadSerializer.voidsetCmsVersionHelper(CMSVersionHelper cmsVersionHelper)voidsetCollectionHelper(CollectionHelper collectionHelper)voidsetCommonI18NService(CommonI18NService commonI18NService)voidsetConverterProvider(AttributeStrategyConverterProvider<VersionAttributeDescriptor> converterProvider)voidsetCustomConverterProvider(CustomAttributeStrategyConverterProvider customConverterProvider)voidsetIsCollectionPredicate(java.util.function.Predicate<AttributeDescriptorModel> isCollectionPredicate)voidsetModelService(ModelService modelService)voidsetPayloadSerializer(PayloadSerializer payloadSerializer)
-
-
-
Method Detail
-
convert
public java.lang.String convert(ItemModel itemModel)
Description copied from interface:ConverterUses the sourceSobject and produces an new instance ofT.
-
getConvertedAttributeValues
protected java.util.Map<java.lang.String,java.lang.Object> getConvertedAttributeValues(ItemModel itemModel)
Returns converted values forItemModelattributes.- Parameters:
itemModel- theItemModelto get the list of attributes and values from.- Returns:
- the
Mapof qualifier and a converted value.
-
getCustomConvertedAttributeValues
protected java.util.Map<java.lang.String,java.lang.Object> getCustomConvertedAttributeValues(ItemModel itemModel)
Returns converted values for custom attributes.- Parameters:
itemModel- theItemModelto get the custom attribute from.- Returns:
- the
Mapof qualifier and a converted value.
-
getAttributeRelatedData
protected java.util.function.Function<AttributeDescriptorModel,java.util.Optional<java.lang.Object>> getAttributeRelatedData(java.util.function.Supplier<java.lang.Object> localizedCollectionGetter, java.util.function.Supplier<java.lang.Object> localizedGetter, java.util.function.Supplier<java.lang.Object> collectionGetter, java.util.function.Supplier<java.lang.Object> simpleGetter)
Returns aFunctionaimed at converting any value described by aAttributeDescriptorModel. This function will execute one of the provided suppliers depending on whether the attribute is localized and/or a collection- Parameters:
localizedCollectionGetter- aSupplierinvoked if the attribute is both localized and a collectionlocalizedGetter- aSupplierinvoked if the attribute is localized and not a collectioncollectionGetter- aSupplierinvoked if the attribute is a collection and not localizedsimpleGetter- aSupplierinvoked if the attribute is neither localized nor a collection- Returns:
- a
Functionto convert a value
-
getAttributeValueMapperForItem
protected java.util.function.Function<AttributeDescriptorModel,java.util.Optional<java.lang.Object>> getAttributeValueMapperForItem(ItemModel itemModel)
Returns a function that acceptsAttributeDescriptorModeland converts attribute value to a format supported byPayloadSerializer.- Parameters:
itemModel- theItemModelthat contains the value for an attribute.- Returns:
- the
Functionthat acceptsAttributeDescriptorModelas a parameter and returns converted value wrapped inside a class supported byPayloadSerializer. Can be null.
-
prepareLocalizedValueForSerialization
protected LocalizedAttributesList prepareLocalizedValueForSerialization(AttributeDescriptorModel attribute, java.util.Map<LanguageModel,java.lang.Object> localizedValues)
Packs the converted localized value inside a class supported byPayloadSerializer.- Parameters:
attribute- theAttributeDescriptorModeldescribing the metadata of the property.localizedValues- theMapthat contains converted localized value.- Returns:
- the
LocalizedAttributesList.
-
prepareSimpleValueForSerialization
protected SLDDataContainer.AttributeValue prepareSimpleValueForSerialization(AttributeDescriptorModel attribute, java.lang.Object convertedValue)
Packs the converted value inside a class supported byPayloadSerializer.- Parameters:
attribute- theAttributeDescriptorModeldescribing the metadata of the property.convertedValue- the converted value- Returns:
- the
SLDDataContainer.AttributeValue.
-
getVersionAttribute
protected VersionAttributeDescriptor getVersionAttribute(AttributeDescriptorModel attribute)
ReturnsVersionAttributeDescriptorbased onAttributeDescriptorModel. TheVersionAttributeDescriptorcontains the type of an element that have to be converted. If theAttributeDescriptorModelrepresents localized collection then theVersionAttributeDescriptorcontains the metadata of the localized collection element. If theAttributeDescriptorModelrepresents localized value then theVersionAttributeDescriptorcontains the metadata of the localized value. If theAttributeDescriptorModelrepresents collection then theVersionAttributeDescriptorcontains the metadata of the collection element. If theAttributeDescriptorModelrepresents simple value then theVersionAttributeDescriptorcontains the metadata of the simple value.- Parameters:
attribute- theAttributeDescriptorModeldescribing the metadata of the property.- Returns:
- the
VersionAttributeDescriptordescribing the metadata of the element represented byAttributeDescriptorModel. Can be null.
-
buildVersionAttributeDescriptor
protected VersionAttributeDescriptor buildVersionAttributeDescriptor(TypeModel typeModel, AttributeDescriptorModel attribute)
-
getMapOfLanguages
protected java.util.Map<LanguageModel,java.lang.Object> getMapOfLanguages(ItemModel itemModel, AttributeDescriptorModel attribute)
Method generates theMapof theLanguageModeland theObjectthat represents the value for the language.- Parameters:
itemModel- theItemModelto retrieve the localized value from.attribute- theAttributeDescriptorModeldescribing the metadata of the property.- Returns:
- the
Mapof theLanguageModeland theObject.
-
getAttributeValueFromItem
protected java.util.Optional<java.lang.Object> getAttributeValueFromItem(ItemModel itemModel, AttributeDescriptorModel attribute, java.util.Locale locale)
Extracts the value from itemModel based on attribute qualifier and locale.- Parameters:
itemModel- theItemModelto retrieve the value from.attribute- theAttributeDescriptorModeldescribing the metadata of the property.locale- theLocale- Returns:
- the
Optionalvalue
-
getAttributeValueFromItem
protected java.util.Optional<java.lang.Object> getAttributeValueFromItem(ItemModel itemModel, AttributeDescriptorModel attribute)
Extracts the value from itemModel based on attribute qualifier.- Parameters:
itemModel- theItemModelto retrieve the value from.attribute- theAttributeDescriptorModeldescribing the metadata of the property.- Returns:
- the
Optionalvalue
-
convertLocalizedValue
protected java.util.Map<LanguageModel,java.lang.Object> convertLocalizedValue(ItemModel itemModel, AttributeDescriptorModel attribute, java.util.function.Function<java.lang.Object,java.lang.Object> converter)
Converts the localized attribute value.- Parameters:
itemModel- theItemModelto retrieve the localized value from.attribute- theAttributeDescriptorModeldescribing the metadata of the property.converter- the conversionFunctionthat will be applied on each element of the localized value.- Returns:
- the
MapofLanguageModelandObjectwhere theObjectrepresents the value.
-
convertCollection
protected java.util.Collection<java.lang.Object> convertCollection(VersionAttributeDescriptor versionAttributeDescriptor, java.util.Collection<java.lang.Object> collection)
Converts collection ofObjectelements.- Parameters:
versionAttributeDescriptor- theVersionAttributeDescriptordescribing the metadata of the collection element.collection- theCollectionthat will be converted.- Returns:
Collectionof converted elements.
-
convertAttributeValue
protected java.lang.Object convertAttributeValue(VersionAttributeDescriptor attribute, java.lang.Object attributeValue)
Converts an attribute value to a format supported byPayloadSerializer.- Parameters:
attribute- attribute theAttributeDescriptorModeldescribing the metadata of the property.attributeValue- theObjectrepresenting the value- Returns:
- converted value supported by
PayloadSerializer.
-
getPayloadSerializer
protected PayloadSerializer getPayloadSerializer()
-
setPayloadSerializer
public void setPayloadSerializer(PayloadSerializer payloadSerializer)
-
getCommonI18NService
protected CommonI18NService getCommonI18NService()
-
setCommonI18NService
public void setCommonI18NService(CommonI18NService commonI18NService)
-
getModelService
protected ModelService getModelService()
-
setModelService
public void setModelService(ModelService modelService)
-
getConverterProvider
protected AttributeStrategyConverterProvider<VersionAttributeDescriptor> getConverterProvider()
-
setConverterProvider
public void setConverterProvider(AttributeStrategyConverterProvider<VersionAttributeDescriptor> converterProvider)
-
getCustomConverterProvider
protected CustomAttributeStrategyConverterProvider getCustomConverterProvider()
-
setCustomConverterProvider
public void setCustomConverterProvider(CustomAttributeStrategyConverterProvider customConverterProvider)
-
getCollectionHelper
protected CollectionHelper getCollectionHelper()
-
setCollectionHelper
public void setCollectionHelper(CollectionHelper collectionHelper)
-
getCmsVersionHelper
protected CMSVersionHelper getCmsVersionHelper()
-
setCmsVersionHelper
public void setCmsVersionHelper(CMSVersionHelper cmsVersionHelper)
-
getIsCollectionPredicate
protected java.util.function.Predicate<AttributeDescriptorModel> getIsCollectionPredicate()
-
setIsCollectionPredicate
public void setIsCollectionPredicate(java.util.function.Predicate<AttributeDescriptorModel> isCollectionPredicate)
-
-