Class CMSVersionToItemModelPopulator
- java.lang.Object
-
- de.hybris.platform.cms2.version.populator.CMSVersionToItemModelPopulator
-
- All Implemented Interfaces:
Populator<AuditPayload,ItemModel>
public class CMSVersionToItemModelPopulator extends java.lang.Object implements Populator<AuditPayload,ItemModel>
Populates a DTO from the payload (AuditPayload) contained in aCMSVersionModel.
-
-
Constructor Summary
Constructors Constructor Description CMSVersionToItemModelPopulator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidapplyAttributeValuesToItemModel(ItemModel itemModel, java.util.Map<java.lang.String,java.lang.Object> values)Applies converted attributes toItemModel.protected voidapplyCustomAttributeValue(ItemModel itemModel, CustomAttributeContentConverter converter, TypedValue typedValue)Applies custom attribute values to theItemModel.protected java.util.Collection<java.lang.Object>collectStreamResult(ValueType valueType, java.util.stream.Stream<java.lang.Object> stream)Applies a properCollectorto a stream usingValueType.protected java.util.function.Function<java.util.List<java.lang.String>,java.lang.Object>convertCollectionValue(ValueType valueType)Returns theFunctionthat converts a collection ofStringvalues toObject.protected voidconvertCustomAttributesValues(ItemModel itemModel, java.util.Map<java.lang.String,TypedValue> values)Converts custom attribute values that are represented byCMSVersionCustomAttribute.protected java.util.Map<java.lang.String,java.lang.Object>convertLocalizedAttributes(java.util.Map<java.lang.String,LocalizedTypedValue> values)Converts the localized attribute values fromAuditPayloadto attribute values ofItemModelprotected java.lang.ObjectconvertLocalizedValue(LocalizedTypedValue localizedTypedValue, java.util.function.Function<java.util.List<java.lang.String>,java.lang.Object> localizedValueConverter)Converts localized value to aMapofLocaleandObject.protected java.util.Map<java.lang.String,java.lang.Object>convertSimpleAttributes(java.util.Map<java.lang.String,TypedValue> values)Converts the attribute values fromAuditPayloadto attribute values ofItemModelprotected java.util.function.Function<java.util.List<java.lang.String>,java.lang.Object>convertSimpleValue(ValueType valueType)Returns theFunctionthat converts a collection containing oneStringelement toObject.protected java.util.function.Function<ValueType,java.util.Optional<java.lang.Object>>getAttributeRelatedData(java.util.function.Supplier<java.lang.Object> collectionGetter, java.util.function.Supplier<java.lang.Object> simpleGetter)Returns aFunctionaimed at converting any value described by aValueType.protected java.util.function.Function<LocalizedTypedValue,java.util.Optional<java.lang.Object>>getAttributeValueMapperForLocalizedTypedValue()Returns aFunctionaimed at converting any localized value described by aLocalizedTypedValue.protected java.util.function.Function<TypedValue,java.util.Optional<java.lang.Object>>getAttributeValueMapperForTypedValue()Returns aFunctionaimed at converting any non localized value described by aTypedValue.protected CMSVersionHelpergetCmsVersionHelper()protected CollectionHelpergetCollectionHelper()protected CommonI18NServicegetCommonI18NService()protected AttributeStrategyConverterProvider<java.lang.String>getConverterProvider()protected java.util.Optional<CustomAttributeContentConverter>getCustomAttributeConverterByQualifier(java.util.List<CustomAttributeContentConverter> converters, java.lang.String qualifier)Returns thee first found converter for a custom attribute based on the qualifier.protected CustomAttributeStrategyConverterProvidergetCustomConverterProvider()protected java.lang.ObjectgetEmptyCollectionValue(AttributeDescriptorModel attribute)Returns an empty collection based onAttributeDescriptorModeltype.protected java.util.Map<java.lang.String,java.lang.Object>getEmptyCollectionValuesPerQualifier(ItemModel itemModel, AuditPayload auditPayload)Returns theMapthat contains default (empty) collection values for every collection attribute that is null.protected java.util.function.Predicate<AttributeDescriptorModel>getIsCollectionPredicate()protected java.util.LocalegetLocale(LocalizedValue localizedValue)Returns aLocaleforLocalizedValue.protected ModelServicegetModelService()protected booleanisCollectionPayloadType(ValueType valueType)Verifies whether theValueTypefrom payload represents a collection or not.protected booleanisCustomAttributeDataType(java.lang.String payloadType)Verifies whether the payloadType represents theCMSVersionCustomAttributeor not.protected java.util.function.Predicate<AttributeDescriptorModel>isInAuditPayload(AuditPayload payload)Verifies that the value of an attribute is inAuditPayload.voidpopulate(AuditPayload auditPayload, ItemModel itemModel)Populate the target instance with values from the source instance.voidsetCmsVersionHelper(CMSVersionHelper cmsVersionHelper)voidsetCollectionHelper(CollectionHelper collectionHelper)voidsetCommonI18NService(CommonI18NService commonI18NService)voidsetConverterProvider(AttributeStrategyConverterProvider<java.lang.String> converterProvider)voidsetCustomConverterProvider(CustomAttributeStrategyConverterProvider customConverterProvider)voidsetIsCollectionPredicate(java.util.function.Predicate<AttributeDescriptorModel> isCollectionPredicate)voidsetModelService(ModelService modelService)
-
-
-
Method Detail
-
populate
public void populate(AuditPayload auditPayload, ItemModel itemModel)
Description copied from interface:PopulatorPopulate the target instance with values from the source instance.- Specified by:
populatein interfacePopulator<AuditPayload,ItemModel>- Parameters:
auditPayload- the source objectitemModel- the target to fill
-
convertSimpleAttributes
protected java.util.Map<java.lang.String,java.lang.Object> convertSimpleAttributes(java.util.Map<java.lang.String,TypedValue> values)
Converts the attribute values fromAuditPayloadto attribute values ofItemModel- Parameters:
values- the list of attributes fromAuditPayload- Returns:
- the list of attributes applicable for
ItemModel
-
convertLocalizedAttributes
protected java.util.Map<java.lang.String,java.lang.Object> convertLocalizedAttributes(java.util.Map<java.lang.String,LocalizedTypedValue> values)
Converts the localized attribute values fromAuditPayloadto attribute values ofItemModel- Parameters:
values- the list of localized attributes fromAuditPayload- Returns:
- the list of localized attributes applicable for
ItemModel
-
getAttributeValueMapperForTypedValue
protected java.util.function.Function<TypedValue,java.util.Optional<java.lang.Object>> getAttributeValueMapperForTypedValue()
Returns aFunctionaimed at converting any non localized value described by aTypedValue.- Returns:
- a
Functionto convert a non localized value.
-
getAttributeValueMapperForLocalizedTypedValue
protected java.util.function.Function<LocalizedTypedValue,java.util.Optional<java.lang.Object>> getAttributeValueMapperForLocalizedTypedValue()
Returns aFunctionaimed at converting any localized value described by aLocalizedTypedValue.- Returns:
- the
Functionto convert a localized value.
-
convertLocalizedValue
protected java.lang.Object convertLocalizedValue(LocalizedTypedValue localizedTypedValue, java.util.function.Function<java.util.List<java.lang.String>,java.lang.Object> localizedValueConverter)
Converts localized value to aMapofLocaleandObject.- Parameters:
localizedTypedValue- theLocalizedTypedValuevalue.localizedValueConverter- theFunctionthat converts the list ofStringvalues toObject.- Returns:
- the
Mapthat contains localized values.
-
convertCollectionValue
protected java.util.function.Function<java.util.List<java.lang.String>,java.lang.Object> convertCollectionValue(ValueType valueType)
Returns theFunctionthat converts a collection ofStringvalues toObject.- Parameters:
valueType- theValueTypedescribing the metadata of the payload's attribute- Returns:
- the
Function.
-
convertSimpleValue
protected java.util.function.Function<java.util.List<java.lang.String>,java.lang.Object> convertSimpleValue(ValueType valueType)
Returns theFunctionthat converts a collection containing oneStringelement toObject.- Parameters:
valueType- theValueTypedescribing the metadata of the payload's attribute.- Returns:
- the
Function.
-
applyAttributeValuesToItemModel
protected void applyAttributeValuesToItemModel(ItemModel itemModel, java.util.Map<java.lang.String,java.lang.Object> values)
Applies converted attributes toItemModel.- Parameters:
itemModel- theItemModelto apply the attribute values.values- theMapof attribute values.
-
isInAuditPayload
protected java.util.function.Predicate<AttributeDescriptorModel> isInAuditPayload(AuditPayload payload)
Verifies that the value of an attribute is inAuditPayload.- Parameters:
payload- theAuditPayloadto verify the attribute on.- Returns:
- false if the attribute is not in
AuditPayload, true otherwise.
-
getEmptyCollectionValuesPerQualifier
protected java.util.Map<java.lang.String,java.lang.Object> getEmptyCollectionValuesPerQualifier(ItemModel itemModel, AuditPayload auditPayload)
Returns theMapthat contains default (empty) collection values for every collection attribute that is null.- Parameters:
itemModel- theItemModelto verify attributes on.- Returns:
- the
Map.
-
getEmptyCollectionValue
protected java.lang.Object getEmptyCollectionValue(AttributeDescriptorModel attribute)
Returns an empty collection based onAttributeDescriptorModeltype.- Parameters:
attribute- a collectionAttributeDescriptorModel.- Returns:
- empty representation of a collection.
-
getLocale
protected java.util.Locale getLocale(LocalizedValue localizedValue)
Returns aLocaleforLocalizedValue.- Parameters:
localizedValue- theLocalizedValue.- Returns:
- the
Locale.
-
collectStreamResult
protected java.util.Collection<java.lang.Object> collectStreamResult(ValueType valueType, java.util.stream.Stream<java.lang.Object> stream)
Applies a properCollectorto a stream usingValueType.- Parameters:
valueType- theValueTypethat is used to extract the collection type of a payload's attribute.stream- theStreamto which the collector should be applied.- Returns:
- the
Collection.
-
getAttributeRelatedData
protected java.util.function.Function<ValueType,java.util.Optional<java.lang.Object>> getAttributeRelatedData(java.util.function.Supplier<java.lang.Object> collectionGetter, java.util.function.Supplier<java.lang.Object> simpleGetter)
Returns aFunctionaimed at converting any value described by aValueType. This function will execute one of the provided suppliers depending on whether the value is a collection or not.
-
convertCustomAttributesValues
protected void convertCustomAttributesValues(ItemModel itemModel, java.util.Map<java.lang.String,TypedValue> values)
Converts custom attribute values that are represented byCMSVersionCustomAttribute.- Parameters:
itemModel- theItemModelto which the custom attributes are applied.values- the list of non localized attributes from the payload.
-
getCustomAttributeConverterByQualifier
protected java.util.Optional<CustomAttributeContentConverter> getCustomAttributeConverterByQualifier(java.util.List<CustomAttributeContentConverter> converters, java.lang.String qualifier)
Returns thee first found converter for a custom attribute based on the qualifier.- Parameters:
converters- the list ofCustomAttributeContentConverter.qualifier- the target qualifier for which the converter should be returned- Returns:
- the
OptionalofCustomAttributeContentConverter.
-
applyCustomAttributeValue
protected void applyCustomAttributeValue(ItemModel itemModel, CustomAttributeContentConverter converter, TypedValue typedValue)
Applies custom attribute values to theItemModel.- Parameters:
itemModel- theItemModelto which the custom attributes are applied.converter- theCustomAttributeContentConverter.typedValue- theTypedValuethat contains the value/values that must be applied toItemModel.
-
isCustomAttributeDataType
protected boolean isCustomAttributeDataType(java.lang.String payloadType)
Verifies whether the payloadType represents theCMSVersionCustomAttributeor not.- Parameters:
payloadType- the type to verify.- Returns:
- true if the payloadType represents
CMSVersionCustomAttribute, false otherwise. Suppress sonar warning (squid:S1166 | Exception handlers should preserve the original exception) : The exception is correctly handled in the catch clause.
-
isCollectionPayloadType
protected boolean isCollectionPayloadType(ValueType valueType)
Verifies whether theValueTypefrom payload represents a collection or not.
-
getCollectionHelper
protected CollectionHelper getCollectionHelper()
-
setCollectionHelper
public void setCollectionHelper(CollectionHelper collectionHelper)
-
getCmsVersionHelper
protected CMSVersionHelper getCmsVersionHelper()
-
setCmsVersionHelper
public void setCmsVersionHelper(CMSVersionHelper cmsVersionHelper)
-
getCommonI18NService
protected CommonI18NService getCommonI18NService()
-
setCommonI18NService
public void setCommonI18NService(CommonI18NService commonI18NService)
-
getCustomConverterProvider
protected CustomAttributeStrategyConverterProvider getCustomConverterProvider()
-
setCustomConverterProvider
public void setCustomConverterProvider(CustomAttributeStrategyConverterProvider customConverterProvider)
-
getModelService
protected ModelService getModelService()
-
setModelService
public void setModelService(ModelService modelService)
-
getConverterProvider
protected AttributeStrategyConverterProvider<java.lang.String> getConverterProvider()
-
setConverterProvider
public void setConverterProvider(AttributeStrategyConverterProvider<java.lang.String> converterProvider)
-
getIsCollectionPredicate
protected java.util.function.Predicate<AttributeDescriptorModel> getIsCollectionPredicate()
-
setIsCollectionPredicate
public void setIsCollectionPredicate(java.util.function.Predicate<AttributeDescriptorModel> isCollectionPredicate)
-
-