Class DefaultCMSVersionToDataConverter
java.lang.Object
de.hybris.platform.cms2.version.converter.impl.DefaultCMSVersionToDataConverter
Default implementation of
ItemModel to String converter for versioning.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected VersionAttributeDescriptorbuildVersionAttributeDescriptor(TypeModel typeModel, AttributeDescriptorModel attribute) Uses the sourceSobject and produces an new instance ofT.protected ObjectconvertAttributeValue(VersionAttributeDescriptor attribute, Object attributeValue) Converts an attribute value to a format supported byPayloadSerializer.protected Collection<Object>convertCollection(VersionAttributeDescriptor versionAttributeDescriptor, Collection<Object> collection) Converts collection ofObjectelements.protected Map<LanguageModel,Object> convertLocalizedValue(ItemModel itemModel, AttributeDescriptorModel attribute, Function<Object, Object> converter) Converts the localized attribute value.protected Function<AttributeDescriptorModel,Optional<Object>> getAttributeRelatedData(Supplier<Object> localizedCollectionGetter, Supplier<Object> localizedGetter, Supplier<Object> collectionGetter, Supplier<Object> simpleGetter) Returns aFunctionaimed at converting any value described by aAttributeDescriptorModel.getAttributeValueFromItem(ItemModel itemModel, AttributeDescriptorModel attribute) Extracts the value from itemModel based on attribute qualifier.getAttributeValueFromItem(ItemModel itemModel, AttributeDescriptorModel attribute, Locale locale) Extracts the value from itemModel based on attribute qualifier and locale.protected Function<AttributeDescriptorModel,Optional<Object>> getAttributeValueMapperForItem(ItemModel itemModel) Returns a function that acceptsAttributeDescriptorModeland converts attribute value to a format supported byPayloadSerializer.protected CMSVersionHelperprotected CollectionHelperprotected CommonI18NServicegetConvertedAttributeValues(ItemModel itemModel) Returns converted values forItemModelattributes.getCustomConvertedAttributeValues(ItemModel itemModel) Returns converted values for custom attributes.protected CustomAttributeStrategyConverterProviderprotected Predicate<AttributeDescriptorModel>protected Map<LanguageModel,Object> getMapOfLanguages(ItemModel itemModel, AttributeDescriptorModel attribute) Method generates theMapof theLanguageModeland theObjectthat represents the value for the language.protected ModelServiceprotected PayloadSerializergetProperAttributeMapping(ItemModel itemModel, AttributeDescriptorModel attribute, VersionAttributeDescriptor versionAttributeDescriptor) protected VersionAttributeDescriptorgetVersionAttribute(AttributeDescriptorModel attribute) ReturnsVersionAttributeDescriptorbased onAttributeDescriptorModel.protected LocalizedAttributesListprepareLocalizedValueForSerialization(AttributeDescriptorModel attribute, Map<LanguageModel, Object> localizedValues) Packs the converted localized value inside a class supported byPayloadSerializer.protected SLDDataContainer.AttributeValueprepareSimpleValueForSerialization(AttributeDescriptorModel attribute, 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(Predicate<AttributeDescriptorModel> isCollectionPredicate) voidsetModelService(ModelService modelService) voidsetPayloadSerializer(PayloadSerializer payloadSerializer)
-
Constructor Details
-
DefaultCMSVersionToDataConverter
public DefaultCMSVersionToDataConverter()
-
-
Method Details
-
convert
Description copied from interface:ConverterUses the sourceSobject and produces an new instance ofT. -
getConvertedAttributeValues
Returns converted values forItemModelattributes. -
getCustomConvertedAttributeValues
Returns converted values for custom attributes. -
getAttributeRelatedData
protected Function<AttributeDescriptorModel,Optional<Object>> getAttributeRelatedData(Supplier<Object> localizedCollectionGetter, Supplier<Object> localizedGetter, Supplier<Object> collectionGetter, Supplier<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 Function<AttributeDescriptorModel,Optional<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.
-
getProperAttributeMapping
protected Optional<Object> getProperAttributeMapping(ItemModel itemModel, AttributeDescriptorModel attribute, VersionAttributeDescriptor versionAttributeDescriptor) -
prepareLocalizedValueForSerialization
protected LocalizedAttributesList prepareLocalizedValueForSerialization(AttributeDescriptorModel attribute, Map<LanguageModel, 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, 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
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 Map<LanguageModel,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 Optional<Object> getAttributeValueFromItem(ItemModel itemModel, AttributeDescriptorModel attribute, 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 Optional<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 Map<LanguageModel,Object> convertLocalizedValue(ItemModel itemModel, AttributeDescriptorModel attribute, Function<Object, 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 Collection<Object> convertCollection(VersionAttributeDescriptor versionAttributeDescriptor, Collection<Object> collection) Converts collection ofObjectelements.- Parameters:
versionAttributeDescriptor- theVersionAttributeDescriptordescribing the metadata of the collection element.collection- theCollectionthat will be converted.- Returns:
Collectionof converted elements.
-
convertAttributeValue
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
-
setPayloadSerializer
-
getCommonI18NService
-
setCommonI18NService
-
getModelService
-
setModelService
-
getConverterProvider
-
setConverterProvider
public void setConverterProvider(AttributeStrategyConverterProvider<VersionAttributeDescriptor> converterProvider) -
getCustomConverterProvider
-
setCustomConverterProvider
public void setCustomConverterProvider(CustomAttributeStrategyConverterProvider customConverterProvider) -
getCollectionHelper
-
setCollectionHelper
-
getCmsVersionHelper
-
setCmsVersionHelper
-
getIsCollectionPredicate
-
setIsCollectionPredicate
-