Class DefaultCMSItemConverter
java.lang.Object
de.hybris.platform.cmsfacades.cmsitems.converter.DefaultCMSItemConverter
- All Implemented Interfaces:
CMSItemConverter
The CMSItemConverter is the first layer of converters applied to convert a given
CMSItemModel into
Map<String, Object>. The reason why this class accepts any kind of ItemModel is that this same
converter will be reused recursively when attributes are part of (AttributeDescriptorModel.getPartOf()) the
enclosing item model, hence denoting a composition. This converter is also handling localized attributes and
collections.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddTransformedCollection(AttributeDescriptorModel attribute, Function<Object, Object> transform, AtomicInteger counter, Collection<Object> transformedCollection, Object value) protected ObjectbuildAttributeContentConverter(AttributeDescriptorModel attribute, Object value) buildAttributeValue(Object source, ItemModel itemModel, AttributeDescriptorModel attribute) protected voidbuildConversionExceptionForSimpleGetter(Object source, AttributeDescriptorModel attribute, ConversionException e) protected ObjectbuildTransformValue(AttributeDescriptorModel attribute, Function<Object, Object> transform, String language, Object value) protected voidcollectValidationErrors(ValidationException e, Optional<String> language, Optional<Integer> position) Collects the errors in the validation exception and adds to the global validation context.protected ItemModelconvertAndValidate(Map<String, Object> map, ComposedTypeModel composedType) protected voidconvertAndValidateAttribute(Map<String, Object> map, ItemModel itemModel, AttributeDescriptorModel attribute) protected Function<AttributeDescriptorModel,Optional<Object>> Function that returns the serializable representation value (String, Map or Collection) of allAttributeDescriptorModelof a given ItemModel source.protected Function<AttributeDescriptorModel,Optional<Object>> Deprecated, for removal: This API element is subject to removal in a future version.since 1811.protected Function<AttributeDescriptorModel,Optional<Object>> convertRepresentationToAttributeValue(Object source, ItemModel itemModel) Function that constructs the persistable representation of allAttributeDescriptorModelof a given serializable source (String, Map or Collection).protected List<AttributeDescriptorModel>getAttributes(ComposedTypeModel composedType) Returns the list of all attributes defined for a given composed type, including the inherited ones.protected Function<AttributeDescriptorModel,Optional<Object>> getAttributeValue(Supplier<Object> localizedCollectionGetter, Supplier<Object> localizedGetter, Supplier<Object> collectionGetter, Supplier<Object> simpleGetter) Returns aFunctionaimed at converting any value described by aAttributeDescriptorModel.protected Function<ItemModel,Map<AttributeDescriptorModel, Object>> Function to get a Map of attribute descriptors and itsObjectvalue for a givenItemModelprotected AttributeValueToRepresentationStrategyprotected AttributeContentValidatorprotected AttributeStrategyConverterProviderprotected CloneComponentContextProviderprotected ItemModelgetCloneModelFromRepresentation(String sourceComponentUuid) Create a Clone Item Model and saves it to theCloneComponentContextProvideror get a Clone Item Model from theCloneComponentContextProviderprotected CMSAdminItemServiceprotected CMSItemValidator<ItemModel>getCmsItemValidator(Map<String, Object> map) protected CMSPermissionCheckerprotected CMSUserServiceprotected ComponentCloningStrategyprotected AttributeContentValidatorprotected Predicate<AttributeDescriptorModel>protected ItemModelGet Item Model from request payloadprotected LocalizedPopulatorprotected ModelServiceprotected OriginalClonedItemProvider<ItemModel>protected CMSItemContextProvider<Map<String,Object>> protected PermissionCRUDServiceprotected TypeServiceprotected UniqueItemIdentifierServiceprotected ValidationErrorsProviderprotected booleaninitializeCloneComponentAttributeContext(String qualifier, Object targetValue) Check that the value for the given qualifier was modified during the cloning process and stores the source component attribute value in the clone component context in the session.protected booleanisCloneComponentFlow(Map<String, Object> map) Determine if a map that represents the item model is a component cloneprotected booleanisDynamicAttribute(AttributeDescriptorModel attribute) Returns true if the attribute is a dynamic attribute.Given anAttributeDescriptorModel, will return aFunctionthat will do the following:
if the attribute is a partOf of the owning type, it will return a conversion of it by means ofconvert(Map<String, Object>)
if the attribute is not a partOf of the owning type, it will return a conversion of it by means of the appropriate data-to-model converter returned by the attributeStrategyConverter.Given anAttributeDescriptorModel, will return aFunctionthat will do the following:
if the attribute is a partOf of the owning type, it will return a conversion of it by means ofconvert(ItemModel)
if the attribute is not a partOf of the owning type, it will return a conversion of it by means of the appropriate model-to-data converter returned by the attributeStrategyConverter.protected booleanmodelHasAssignedUUID(Map<String, Object> valueMap) protected booleanprincipalCanUpdateAttribute(String typeCode, String qualifier) This method determines whether the current principal can update the attribute identified by the qualifier in the enclosing type.protected booleanprincipalCanWriteAttributeLanguage(String qualifier, String languageIsoCode, Set<String> writeableLanguages) This method is used to check if the current principal can write a language of a localized attribute.voidsetAttributeStrategyConverter(AttributeStrategyConverterProvider attributeStrategyConverter) voidsetAttributeValueToRepresentationStrategy(AttributeValueToRepresentationStrategy attributeValueToRepresentationStrategy) voidsetBaseAttributeContentValidator(AttributeContentValidator baseAttributeContentValidator) voidsetCloneAttributeStrategyConverter(AttributeStrategyConverterProvider cloneAttributeStrategyConverter) voidsetCloneComponentContextProvider(CloneComponentContextProvider cloneComponentContextProvider) voidsetCmsAdminItemService(CMSAdminItemService cmsAdminItemService) voidsetCmsItemAttributeFilterEnablerService(CMSItemAttributeFilterEnablerService cmsItemAttributeFilterEnablerService) voidsetCmsItemValidatorCreate(CMSItemValidator<ItemModel> cmsItemValidatorCreate) voidsetCmsItemValidatorUpdate(CMSItemValidator<ItemModel> cmsItemValidatorUpdate) voidsetCmsPermissionChecker(CMSPermissionChecker cmsPermissionChecker) voidsetCmsUserService(CMSUserService cmsUserService) voidsetComponentCloningStrategy(ComponentCloningStrategy componentCloningStrategy) voidsetComposedTypeToAttributeCollectionConverter(ComposedTypeToAttributeCollectionConverter composedTypeToAttributeCollectionConverter) voidvoidsetExtendedAttributeContentValidator(AttributeContentValidator extendedAttributeContentValidator) voidsetIsCollectionPredicate(Predicate<AttributeDescriptorModel> isCollectionPredicate) voidsetLocalizedPopulator(LocalizedPopulator localizedPopulator) voidsetModelService(ModelService modelService) voidsetNestedOrPartOfAttributePredicate(NestedOrPartOfAttributePredicate nestedOrPartOfAttributePredicate) voidsetOriginalClonedItemProvider(OriginalClonedItemProvider<ItemModel> originalClonedItemProvider) voidsetOriginalConvertedItemProvider(CMSItemContextProvider<Map<String, Object>> originalConvertedItemProvider) voidsetPermissionCRUDService(PermissionCRUDService permissionCRUDService) voidsetTypeService(TypeService typeService) voidsetUniqueItemIdentifierService(UniqueItemIdentifierService uniqueItemIdentifierService) voidsetValidatableService(ValidatableService validatableService) voidsetValidationErrorsProvider(ValidationErrorsProvider validationErrorsProvider) protected Collection<Object>transformCollection(AttributeDescriptorModel attribute, Collection<Object> collection, Function<Object, Object> transform) Convenience method to apply a transformation to all elements of aFunctiontransformLocalizedValue(AttributeDescriptorModel attribute, Map<String, Object> itemMap, ItemModel itemModel, Function<Object, Object> transform) Convenience method to apply a transformation to values of aMaptransformLocalizedValue(AttributeDescriptorModel attribute, Map<String, Object> itemMap, Function<Object, Object> transform) Deprecated, for removal: This API element is subject to removal in a future version.since 1811.protected voidvalidate(Object value, AttributeDescriptorModel attribute, AttributeContentValidator validator) Validates and throws an exception if there are validation errors
-
Constructor Details
-
DefaultCMSItemConverter
public DefaultCMSItemConverter()
-
-
Method Details
-
convert
Description copied from interface:CMSItemConverter- Specified by:
convertin interfaceCMSItemConverter- Parameters:
source- theItemModelto convert.- Returns:
- the
ItemModelconverted to aMap
-
convert
Description copied from interface:CMSItemConverter- Specified by:
convertin interfaceCMSItemConverter- Parameters:
map- the Map<String, Object> to convert- Returns:
- the
Mapconverted to anItemModel
-
convertAndValidate
-
convertAndValidateAttribute
protected void convertAndValidateAttribute(Map<String, Object> map, ItemModel itemModel, AttributeDescriptorModel attribute) Converts and validates a primitive data or deserializableMapto an attribute value (primitive orItemModel).- Parameters:
map- the Map<String, Object> containing the attribute data to convertitemModel- the model which attribute value will be updatedattribute- the attribute descriptor providing information about the attribute to be updated
-
initializeCloneComponentAttributeContext
Check that the value for the given qualifier was modified during the cloning process and stores the source component attribute value in the clone component context in the session.- Parameters:
qualifier- the attribute field nametargetValue- the value to be applied to the component model- Returns:
- TRUE when the attribute value was modified during the component cloning flow;
FALSE when the given qualifier isUIDor when the attribute value was not modified
-
getCmsItemValidator
-
getItemModelFromRepresentation
Get Item Model from request payload- Parameters:
map- the map representing the Item Model- Returns:
- the ItemModel related to this Map representation
-
isCloneComponentFlow
Determine if a map that represents the item model is a component clone- Parameters:
map- the map representing the Item Model- Returns:
- a boolean that determines if the item being created is a component clone
-
getCloneModelFromRepresentation
Create a Clone Item Model and saves it to theCloneComponentContextProvideror get a Clone Item Model from theCloneComponentContextProvider- Parameters:
sourceComponentUuid- the UUID representing the source Item Model to clone from- Returns:
- the ItemModel cloned from the provided
sourceComponentUuid
-
transformCollection
protected Collection<Object> transformCollection(AttributeDescriptorModel attribute, Collection<Object> collection, Function<Object, Object> transform) Convenience method to apply a transformation to all elements of aFunction- Parameters:
collection- theCollectionthe elements of which we need to transformtransform- the transformationFunctionthat will be applied on each element of the collection- Returns:
- a new collection
-
addTransformedCollection
protected void addTransformedCollection(AttributeDescriptorModel attribute, Function<Object, Object> transform, AtomicInteger counter, Collection<Object> transformedCollection, Object value) -
transformLocalizedValue
protected Map<String,Object> transformLocalizedValue(AttributeDescriptorModel attribute, Map<String, Object> itemMap, ItemModel itemModel, Function<Object, Object> transform) Convenience method to apply a transformation to values of aMap- Parameters:
itemMap- theMapthe values of which we need to transformitemModel- the model containing the original attribute value. If this is a new model, the attribute value will be empty.transform- the transformationFunctionthat will be applied on each values of the itemMap- Returns:
- a new itemMap
-
buildTransformValue
-
leafOrDeeperConvertToRepresentation
protected Function<Object,Object> leafOrDeeperConvertToRepresentation(AttributeDescriptorModel attribute) Given anAttributeDescriptorModel, will return aFunctionthat will do the following:
if the attribute is a partOf of the owning type, it will return a conversion of it by means ofconvert(ItemModel)
if the attribute is not a partOf of the owning type, it will return a conversion of it by means of the appropriate model-to-data converter returned by the attributeStrategyConverter.- Parameters:
attribute- theAttributeDescriptorModeldescribing the metadata of the property of a class- Returns:
- a conversion of type Object
-
leafOrDeeperConvertToModel
Given anAttributeDescriptorModel, will return aFunctionthat will do the following:
if the attribute is a partOf of the owning type, it will return a conversion of it by means ofconvert(Map<String, Object>)
if the attribute is not a partOf of the owning type, it will return a conversion of it by means of the appropriate data-to-model converter returned by the attributeStrategyConverter. if no converter is found,AttributeContentConverter.Value.NOT_TO_BE_SETis returned to instruct no to try to persist this property- Parameters:
attribute- theAttributeDescriptorModeldescribing the metadata of the property of a class- Returns:
- a conversion of type Object
- Throws:
IllegalAccessExceptionInstantiationException
-
buildAttributeContentConverter
-
isDynamicAttribute
Returns true if the attribute is a dynamic attribute. Note that this method doesn't consider RelationDescriptorModels as dynamic.- Parameters:
attribute- The attribute to evaluate.- Returns:
- true if the attribute is dynamic, false otherwise.
-
getAttributes
Returns the list of all attributes defined for a given composed type, including the inherited ones.- Parameters:
composedType- the composedType the attributes belong to- Returns:
- a list of all attributes declared, including inherited attributes.
-
getAttributeValues
Function to get a Map of attribute descriptors and itsObjectvalue for a givenItemModel- Returns:
- a function that when executed returns a map with attributes and their respective values.
-
convertAttributeValueToRepresentation
protected Function<AttributeDescriptorModel,Optional<Object>> convertAttributeValueToRepresentation(ItemModel source) Function that returns the serializable representation value (String, Map or Collection) of allAttributeDescriptorModelof a given ItemModel source. This methods recursively handles the following cases and their possible combinations:- localized field
- collections
- partOf
- Parameters:
source- theItemModelowning all theAttributeDescriptorModel- Returns:
- returns the serializable representations
-
convertRepresentationToAttributeValue
protected Function<AttributeDescriptorModel,Optional<Object>> convertRepresentationToAttributeValue(Object source, ItemModel itemModel) Function that constructs the persistable representation of allAttributeDescriptorModelof a given serializable source (String, Map or Collection). This methods recursively handles the following cases and their possible combinations:- localized field
- collections
- partOf
- Parameters:
source- serializable source (String, Map or Collection) described by aAttributeDescriptorModelitemModel- the model containing the original attribute value. If this is a new model, the attribute value will be empty.- Returns:
- returns the persistable representations
-
getAttributeValue
protected Function<AttributeDescriptorModel,Optional<Object>> getAttributeValue(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 an attribute- Returns:
- a
Functionto convert a value
-
validate
protected void validate(Object value, AttributeDescriptorModel attribute, AttributeContentValidator validator) Validates and throws an exception if there are validation errors- Parameters:
value- the value being validatedattribute- the attribute descriptor modelvalidator- the validator to be used
-
collectValidationErrors
protected void collectValidationErrors(ValidationException e, Optional<String> language, Optional<Integer> position) Collects the errors in the validation exception and adds to the global validation context.- Parameters:
e- the exceptionlanguage- optional; the validated languageposition- optional; the position in which the object value in the collection
-
modelHasAssignedUUID
-
buildAttributeValue
protected Optional<Object> buildAttributeValue(Object source, ItemModel itemModel, AttributeDescriptorModel attribute) -
buildConversionExceptionForSimpleGetter
protected void buildConversionExceptionForSimpleGetter(Object source, AttributeDescriptorModel attribute, ConversionException e) -
principalCanUpdateAttribute
This method determines whether the current principal can update the attribute identified by the qualifier in the enclosing type. A user can update an attribute when both read and change attribute permissions are granted.- Parameters:
typeCode- the item model type codequalifier- the attribute qualifier- Returns:
TRUEwhen the user has read and change permissions on the attribute; otherwiseFALSE
-
principalCanWriteAttributeLanguage
protected boolean principalCanWriteAttributeLanguage(String qualifier, String languageIsoCode, Set<String> writeableLanguages) This method is used to check if the current principal can write a language of a localized attribute.- Parameters:
qualifier- - the qualifier of the attribute whose language wants to be changed.languageIsoCode- - the ISO code of the language that wants to be updated.writeableLanguages- - the list of languages the current principal can write. Each element represents the ISO code of a language- Returns:
- a boolean flag. True, if the user can write the language for the localized element; False, otherwise.
-
convertRepresentationToAttributeValue
@Deprecated(since="1811", forRemoval=true) protected Function<AttributeDescriptorModel,Optional<Object>> convertRepresentationToAttributeValue(Object source) Deprecated, for removal: This API element is subject to removal in a future version.since 1811. Please useconvertRepresentationToAttributeValue(Object, ItemModel)instead.Function that constructs the persistable representation of allAttributeDescriptorModelof a given serializable source (String, Map or Collection). This methods recursively handles the following cases and their possible combinations:- localized field
- collections
- partOf
- Parameters:
source- serializable source (String, Map or Collection) described by aAttributeDescriptorModel- Returns:
- returns the persistable representations
-
transformLocalizedValue
@Deprecated(since="1811", forRemoval=true) protected Map<String,Object> transformLocalizedValue(AttributeDescriptorModel attribute, Map<String, Object> itemMap, Function<Object, Object> transform) Deprecated, for removal: This API element is subject to removal in a future version.since 1811. Please usetransformLocalizedValue(AttributeDescriptorModel, Map, ItemModel, Function)instead.Convenience method to apply a transformation to values of aMap -
getTypeService
-
setTypeService
-
getModelService
-
setModelService
-
getLocalizedPopulator
-
setLocalizedPopulator
-
getAttributeStrategyConverter
-
setAttributeStrategyConverter
public void setAttributeStrategyConverter(AttributeStrategyConverterProvider attributeStrategyConverter) -
getUniqueItemIdentifierService
-
setUniqueItemIdentifierService
-
getCmsAdminItemService
-
setCmsAdminItemService
-
getBaseAttributeContentValidator
-
setBaseAttributeContentValidator
public void setBaseAttributeContentValidator(AttributeContentValidator baseAttributeContentValidator) -
getExtendedAttributeContentValidator
-
setExtendedAttributeContentValidator
public void setExtendedAttributeContentValidator(AttributeContentValidator extendedAttributeContentValidator) -
getValidationErrorsProvider
-
setValidationErrorsProvider
-
getNestedOrPartOfAttributePredicate
-
setNestedOrPartOfAttributePredicate
public void setNestedOrPartOfAttributePredicate(NestedOrPartOfAttributePredicate nestedOrPartOfAttributePredicate) -
getValidatableService
-
setValidatableService
-
getCmsItemValidatorCreate
-
setCmsItemValidatorCreate
-
getCmsItemValidatorUpdate
-
setCmsItemValidatorUpdate
-
getOriginalClonedItemProvider
-
setOriginalClonedItemProvider
public void setOriginalClonedItemProvider(OriginalClonedItemProvider<ItemModel> originalClonedItemProvider) -
getComponentCloningStrategy
-
setComponentCloningStrategy
-
getCloneComponentContextProvider
-
setCloneComponentContextProvider
public void setCloneComponentContextProvider(CloneComponentContextProvider cloneComponentContextProvider) -
getCloneAttributeStrategyConverter
-
setCloneAttributeStrategyConverter
public void setCloneAttributeStrategyConverter(AttributeStrategyConverterProvider cloneAttributeStrategyConverter) -
getAttributeValueToRepresentationStrategy
-
setAttributeValueToRepresentationStrategy
public void setAttributeValueToRepresentationStrategy(AttributeValueToRepresentationStrategy attributeValueToRepresentationStrategy) -
getComposedTypeToAttributeCollectionConverter
protected ComposedTypeToAttributeCollectionConverter getComposedTypeToAttributeCollectionConverter() -
setComposedTypeToAttributeCollectionConverter
public void setComposedTypeToAttributeCollectionConverter(ComposedTypeToAttributeCollectionConverter composedTypeToAttributeCollectionConverter) -
getCustomPopulators
-
setCustomPopulators
-
getPermissionCRUDService
-
setPermissionCRUDService
-
getCmsUserService
-
setCmsUserService
-
getCmsPermissionChecker
-
setCmsPermissionChecker
-
getIsCollectionPredicate
-
setIsCollectionPredicate
-
getOriginalConvertedItemProvider
-
setOriginalConvertedItemProvider
public void setOriginalConvertedItemProvider(CMSItemContextProvider<Map<String, Object>> originalConvertedItemProvider) -
getCmsItemAttributeFilterEnablerService
-
setCmsItemAttributeFilterEnablerService
public void setCmsItemAttributeFilterEnablerService(CMSItemAttributeFilterEnablerService cmsItemAttributeFilterEnablerService)
-