public class DefaultCMSItemConverter extends java.lang.Object implements CMSItemConverter
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 and Description |
|---|
DefaultCMSItemConverter() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
collectValidationErrors(ValidationException e,
java.util.Optional<java.lang.String> language,
java.util.Optional<java.lang.Integer> position)
Collects the errors in the validation exception and adds to the global validation context.
|
java.util.Map<java.lang.String,java.lang.Object> |
convert(ItemModel source)
Converts an
ItemModel to a serializable Map. |
ItemModel |
convert(java.util.Map<java.lang.String,java.lang.Object> map)
Converts a deserializable
Map to an ItemModel. |
protected ItemModel |
convertAndValidate(java.util.Map<java.lang.String,java.lang.Object> map,
ComposedTypeModel composedType)
Converts and validates a deserializable
Map to an ItemModel. |
protected void |
convertAndValidateAttribute(java.util.Map<java.lang.String,java.lang.Object> map,
ItemModel itemModel,
AttributeDescriptorModel attribute)
Converts and validates a primitive data or deserializable
Map to an attribute value (primitive or
ItemModel). |
protected java.util.function.Function<AttributeDescriptorModel,java.util.Optional<java.lang.Object>> |
convertAttributeValueToRepresentation(ItemModel source)
Function that returns the serializable representation value (String, Map or Collection) of all
AttributeDescriptorModel of a given ItemModel source. |
protected java.util.function.Function<AttributeDescriptorModel,java.util.Optional<java.lang.Object>> |
convertRepresentationToAttributeValue(java.lang.Object source)
Deprecated.
since 1811. Please use
convertRepresentationToAttributeValue(Object, ItemModel)
instead. |
protected java.util.function.Function<AttributeDescriptorModel,java.util.Optional<java.lang.Object>> |
convertRepresentationToAttributeValue(java.lang.Object source,
ItemModel itemModel)
Function that constructs the persistable representation of all
AttributeDescriptorModel of a given
serializable source (String, Map or Collection). |
protected java.util.List<AttributeDescriptorModel> |
getAttributes(ComposedTypeModel composedType)
Returns the list of all attributes defined for a given composed type, including the inherited ones.
|
AttributeStrategyConverterProvider |
getAttributeStrategyConverter() |
protected java.util.function.Function<AttributeDescriptorModel,java.util.Optional<java.lang.Object>> |
getAttributeValue(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 a
Function aimed at converting any value described by a AttributeDescriptorModel. |
protected java.util.function.Function<ItemModel,java.util.Map<AttributeDescriptorModel,java.lang.Object>> |
getAttributeValues()
Function to get a Map of attribute descriptors and its
Object value for a given ItemModel |
protected AttributeValueToRepresentationStrategy |
getAttributeValueToRepresentationStrategy() |
protected AttributeContentValidator |
getBaseAttributeContentValidator() |
protected AttributeStrategyConverterProvider |
getCloneAttributeStrategyConverter() |
protected CloneComponentContextProvider |
getCloneComponentContextProvider() |
protected ItemModel |
getCloneModelFromRepresentation(java.lang.String sourceComponentUuid)
Create a Clone Item Model and saves it to the
CloneComponentContextProvider or get a Clone Item Model from
the CloneComponentContextProvider |
protected CMSAdminItemService |
getCmsAdminItemService() |
protected CMSItemValidator<ItemModel> |
getCmsItemValidator(java.util.Map<java.lang.String,java.lang.Object> map) |
CMSItemValidator<ItemModel> |
getCmsItemValidatorCreate() |
CMSItemValidator<ItemModel> |
getCmsItemValidatorUpdate() |
protected CMSPermissionChecker |
getCmsPermissionChecker() |
protected CMSUserService |
getCmsUserService() |
protected ComponentCloningStrategy |
getComponentCloningStrategy() |
protected ComposedTypeToAttributeCollectionConverter |
getComposedTypeToAttributeCollectionConverter() |
protected java.util.List<Populator<ItemModel,java.util.Map<java.lang.String,java.lang.Object>>> |
getCustomPopulators() |
protected Converter<java.util.Date,java.lang.String> |
getDateConverter() |
protected AttributeContentValidator |
getExtendedAttributeContentValidator() |
protected java.util.function.Predicate<AttributeDescriptorModel> |
getIsCollectionPredicate() |
protected ItemModel |
getItemModelFromRepresentation(java.util.Map<java.lang.String,java.lang.Object> map)
Get Item Model from request payload
|
protected LocalizedPopulator |
getLocalizedPopulator() |
protected ModelService |
getModelService() |
NestedOrPartOfAttributePredicate |
getNestedOrPartOfAttributePredicate() |
protected OriginalClonedItemProvider<ItemModel> |
getOriginalClonedItemProvider() |
protected PermissionCRUDService |
getPermissionCRUDService() |
protected TypeService |
getTypeService() |
protected UniqueItemIdentifierService |
getUniqueItemIdentifierService() |
ValidatableService |
getValidatableService() |
protected ValidationErrorsProvider |
getValidationErrorsProvider() |
protected boolean |
initializeCloneComponentAttributeContext(java.lang.String qualifier,
java.lang.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 boolean |
isCloneComponentFlow(java.util.Map<java.lang.String,java.lang.Object> map)
Determine if a map that represents the item model is a component clone
|
protected boolean |
isDynamicAttribute(AttributeDescriptorModel attribute)
Returns true if the attribute is a dynamic attribute.
|
protected java.util.function.Function<java.lang.Object,java.lang.Object> |
leafOrDeeperConvertToModel(AttributeDescriptorModel attribute)
Given an
AttributeDescriptorModel, will return a Function that will do the following: if the attribute is a partOf of the owning type, it will return a conversion of it by means of DefaultCMSItemConverter#convert(Map 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. |
protected java.util.function.Function<java.lang.Object,java.lang.Object> |
leafOrDeeperConvertToRepresentation(AttributeDescriptorModel attribute)
Given an
AttributeDescriptorModel, will return a Function that will do the following: if the attribute is a partOf of the owning type, it will return a conversion of it by means of convert(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 boolean |
modelHasAssignedUUID(java.util.Map<java.lang.String,java.lang.Object> valueMap) |
protected boolean |
principalCanUpdateAttribute(java.lang.String typeCode,
java.lang.String qualifier)
This method determines whether the current principal can update the attribute identified by the qualifier in the
enclosing type.
|
protected boolean |
principalCanWriteAttributeLanguage(java.lang.String qualifier,
java.lang.String languageIsoCode,
java.util.Set<java.lang.String> writeableLanguages)
This method is used to check if the current principal can write a language of a localized attribute.
|
void |
setAttributeStrategyConverter(AttributeStrategyConverterProvider attributeStrategyConverter) |
void |
setAttributeValueToRepresentationStrategy(AttributeValueToRepresentationStrategy attributeValueToRepresentationStrategy) |
void |
setBaseAttributeContentValidator(AttributeContentValidator baseAttributeContentValidator) |
void |
setCloneAttributeStrategyConverter(AttributeStrategyConverterProvider cloneAttributeStrategyConverter) |
void |
setCloneComponentContextProvider(CloneComponentContextProvider cloneComponentContextProvider) |
void |
setCmsAdminItemService(CMSAdminItemService cmsAdminItemService) |
void |
setCmsItemValidatorCreate(CMSItemValidator<ItemModel> cmsItemValidatorCreate) |
void |
setCmsItemValidatorUpdate(CMSItemValidator<ItemModel> cmsItemValidatorUpdate) |
void |
setCmsPermissionChecker(CMSPermissionChecker cmsPermissionChecker) |
void |
setCmsUserService(CMSUserService cmsUserService) |
void |
setComponentCloningStrategy(ComponentCloningStrategy componentCloningStrategy) |
void |
setComposedTypeToAttributeCollectionConverter(ComposedTypeToAttributeCollectionConverter composedTypeToAttributeCollectionConverter) |
void |
setCustomPopulators(java.util.List<Populator<ItemModel,java.util.Map<java.lang.String,java.lang.Object>>> customPopulators) |
void |
setDateConverter(Converter<java.util.Date,java.lang.String> dateConverter)
Deprecated.
since 6.7
|
void |
setExtendedAttributeContentValidator(AttributeContentValidator extendedAttributeContentValidator) |
void |
setIsCollectionPredicate(java.util.function.Predicate<AttributeDescriptorModel> isCollectionPredicate) |
void |
setLocalizedPopulator(LocalizedPopulator localizedPopulator) |
void |
setModelService(ModelService modelService) |
void |
setNestedOrPartOfAttributePredicate(NestedOrPartOfAttributePredicate nestedOrPartOfAttributePredicate) |
void |
setOriginalClonedItemProvider(OriginalClonedItemProvider<ItemModel> originalClonedItemProvider) |
void |
setPermissionCRUDService(PermissionCRUDService permissionCRUDService) |
void |
setTypeService(TypeService typeService) |
void |
setUniqueItemIdentifierService(UniqueItemIdentifierService uniqueItemIdentifierService) |
void |
setValidatableService(ValidatableService validatableService) |
void |
setValidationErrorsProvider(ValidationErrorsProvider validationErrorsProvider) |
protected java.util.Collection<java.lang.Object> |
transformCollection(AttributeDescriptorModel attribute,
java.util.Collection<java.lang.Object> collection,
java.util.function.Function<java.lang.Object,java.lang.Object> transform)
Convenience method to apply a transformation to all elements of a
Function |
protected java.util.Map<java.lang.String,java.lang.Object> |
transformLocalizedValue(AttributeDescriptorModel attribute,
java.util.Map<java.lang.String,java.lang.Object> itemMap,
java.util.function.Function<java.lang.Object,java.lang.Object> transform)
Deprecated.
since 1811. Please use
transformLocalizedValue(AttributeDescriptorModel, Map, ItemModel, Function)
instead. |
protected java.util.Map<java.lang.String,java.lang.Object> |
transformLocalizedValue(AttributeDescriptorModel attribute,
java.util.Map<java.lang.String,java.lang.Object> itemMap,
ItemModel itemModel,
java.util.function.Function<java.lang.Object,java.lang.Object> transform)
Convenience method to apply a transformation to values of a
Map |
protected void |
validate(java.lang.Object value,
AttributeDescriptorModel attribute,
AttributeContentValidator validator)
Validates and throws an exception if there are validation errors
|
public java.util.Map<java.lang.String,java.lang.Object> convert(ItemModel source)
CMSItemConverterItemModel to a serializable Map.convert in interface CMSItemConvertersource - the ItemModel to convert.ItemModel converted to a Mappublic ItemModel convert(java.util.Map<java.lang.String,java.lang.Object> map)
CMSItemConverterMap to an ItemModel.convert in interface CMSItemConvertermap - the MapMap converted to an ItemModelprotected ItemModel convertAndValidate(java.util.Map<java.lang.String,java.lang.Object> map, ComposedTypeModel composedType)
Map to an ItemModel.map - the MapcomposedType - the type to which the Map will be converted to.Map converted to an ItemModelprotected void convertAndValidateAttribute(java.util.Map<java.lang.String,java.lang.Object> map,
ItemModel itemModel,
AttributeDescriptorModel attribute)
Map to an attribute value (primitive or
ItemModel).map - the MapitemModel - the model which attribute value will be updatedattribute - the attribute descriptor providing information about the attribute to be updatedprotected boolean initializeCloneComponentAttributeContext(java.lang.String qualifier,
java.lang.Object targetValue)
qualifier - the attribute field nametargetValue - the value to be applied to the component modelUID or when the attribute value was not modifiedprotected CMSItemValidator<ItemModel> getCmsItemValidator(java.util.Map<java.lang.String,java.lang.Object> map)
protected ItemModel getItemModelFromRepresentation(java.util.Map<java.lang.String,java.lang.Object> map)
map - the map representing the Item Modelprotected boolean isCloneComponentFlow(java.util.Map<java.lang.String,java.lang.Object> map)
map - the map representing the Item Modelprotected ItemModel getCloneModelFromRepresentation(java.lang.String sourceComponentUuid)
CloneComponentContextProvider or get a Clone Item Model from
the CloneComponentContextProvidersourceComponentUuid - the UUID representing the source Item Model to clone fromsourceComponentUuidprotected java.util.Collection<java.lang.Object> transformCollection(AttributeDescriptorModel attribute, java.util.Collection<java.lang.Object> collection, java.util.function.Function<java.lang.Object,java.lang.Object> transform)
Functioncollection - the Collection the elements of which we need to transformtransform - the transformation Function that will be applied on each element of the collectionprotected java.util.Map<java.lang.String,java.lang.Object> transformLocalizedValue(AttributeDescriptorModel attribute, java.util.Map<java.lang.String,java.lang.Object> itemMap, ItemModel itemModel, java.util.function.Function<java.lang.Object,java.lang.Object> transform)
MapitemMap - the Map the 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 transformation Function that will be applied on each values of the itemMapprotected java.util.function.Function<java.lang.Object,java.lang.Object> leafOrDeeperConvertToRepresentation(AttributeDescriptorModel attribute)
AttributeDescriptorModel, will return a Function that will do the following: convert(ItemModel) attribute - the AttributeDescriptorModel describing the metadata of the property of a classprotected java.util.function.Function<java.lang.Object,java.lang.Object> leafOrDeeperConvertToModel(AttributeDescriptorModel attribute)
AttributeDescriptorModel, will return a Function that will do the following: DefaultCMSItemConverter#convert(Map) AttributeContentConverter.Value.NOT_TO_BE_SET is returned to instruct no to try to persist this propertyattribute - the AttributeDescriptorModel describing the metadata of the property of a classjava.lang.IllegalAccessExceptionjava.lang.InstantiationExceptionprotected boolean isDynamicAttribute(AttributeDescriptorModel attribute)
attribute - The attribute to evaluate.protected java.util.List<AttributeDescriptorModel> getAttributes(ComposedTypeModel composedType)
composedType - the composedType the attributes belong toprotected java.util.function.Function<ItemModel,java.util.Map<AttributeDescriptorModel,java.lang.Object>> getAttributeValues()
Object value for a given ItemModelprotected java.util.function.Function<AttributeDescriptorModel,java.util.Optional<java.lang.Object>> convertAttributeValueToRepresentation(ItemModel source)
AttributeDescriptorModel of a given ItemModel source. This methods recursively handles the following cases
and their possible combinations:
source - the ItemModel owning all the AttributeDescriptorModelprotected java.util.function.Function<AttributeDescriptorModel,java.util.Optional<java.lang.Object>> convertRepresentationToAttributeValue(java.lang.Object source, ItemModel itemModel)
AttributeDescriptorModel of a given
serializable source (String, Map or Collection). This methods recursively handles the following cases and their
possible combinations:
source - serializable source (String, Map or Collection) described by a AttributeDescriptorModelitemModel - the model containing the original attribute value. If this is a new model, the attribute value will be
empty.protected java.util.function.Function<AttributeDescriptorModel,java.util.Optional<java.lang.Object>> getAttributeValue(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)
Function aimed at converting any value described by a AttributeDescriptorModel. This
function will execute one of the provided suppliers depending on whether the attribute is localized and/or a
collectionlocalizedCollectionGetter - a Supplier invoked if the attribute is both localized and a collectionlocalizedGetter - a Supplier invoked if the attribute is localized and not a collectioncollectionGetter - a Supplier invoked if the attribute is a collection and not localizedsimpleGetter - a Supplier invoked if the attribute is neither localized nor an attributeFunction to convert a valueprotected void validate(java.lang.Object value,
AttributeDescriptorModel attribute,
AttributeContentValidator validator)
value - the value being validatedattribute - the attribute descriptor modelvalidator - the validator to be usedprotected void collectValidationErrors(ValidationException e, java.util.Optional<java.lang.String> language, java.util.Optional<java.lang.Integer> position)
e - the exceptionlanguage - optional; the validated languageposition - optional; the position in which the object value in the collectionprotected boolean modelHasAssignedUUID(java.util.Map<java.lang.String,java.lang.Object> valueMap)
protected boolean principalCanUpdateAttribute(java.lang.String typeCode,
java.lang.String qualifier)
typeCode - the item model type codequalifier - the attribute qualifierTRUE when the user has read and change permissions on the attribute; otherwise FALSEprotected boolean principalCanWriteAttributeLanguage(java.lang.String qualifier,
java.lang.String languageIsoCode,
java.util.Set<java.lang.String> writeableLanguages)
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@Deprecated protected java.util.function.Function<AttributeDescriptorModel,java.util.Optional<java.lang.Object>> convertRepresentationToAttributeValue(java.lang.Object source)
convertRepresentationToAttributeValue(Object, ItemModel)
instead.AttributeDescriptorModel of a given
serializable source (String, Map or Collection). This methods recursively handles the following cases and their
possible combinations:
source - serializable source (String, Map or Collection) described by a AttributeDescriptorModel@Deprecated protected java.util.Map<java.lang.String,java.lang.Object> transformLocalizedValue(AttributeDescriptorModel attribute, java.util.Map<java.lang.String,java.lang.Object> itemMap, java.util.function.Function<java.lang.Object,java.lang.Object> transform)
transformLocalizedValue(AttributeDescriptorModel, Map, ItemModel, Function)
instead.MapitemMap - the Map the values of which we need to transformtransform - the transformation Function that will be applied on each values of the itemMapprotected TypeService getTypeService()
public void setTypeService(TypeService typeService)
protected ModelService getModelService()
public void setModelService(ModelService modelService)
protected LocalizedPopulator getLocalizedPopulator()
public void setLocalizedPopulator(LocalizedPopulator localizedPopulator)
public AttributeStrategyConverterProvider getAttributeStrategyConverter()
public void setAttributeStrategyConverter(AttributeStrategyConverterProvider attributeStrategyConverter)
protected Converter<java.util.Date,java.lang.String> getDateConverter()
@Deprecated public void setDateConverter(Converter<java.util.Date,java.lang.String> dateConverter)
protected UniqueItemIdentifierService getUniqueItemIdentifierService()
public void setUniqueItemIdentifierService(UniqueItemIdentifierService uniqueItemIdentifierService)
protected CMSAdminItemService getCmsAdminItemService()
public void setCmsAdminItemService(CMSAdminItemService cmsAdminItemService)
protected AttributeContentValidator getBaseAttributeContentValidator()
public void setBaseAttributeContentValidator(AttributeContentValidator baseAttributeContentValidator)
protected AttributeContentValidator getExtendedAttributeContentValidator()
public void setExtendedAttributeContentValidator(AttributeContentValidator extendedAttributeContentValidator)
protected ValidationErrorsProvider getValidationErrorsProvider()
public void setValidationErrorsProvider(ValidationErrorsProvider validationErrorsProvider)
public NestedOrPartOfAttributePredicate getNestedOrPartOfAttributePredicate()
public void setNestedOrPartOfAttributePredicate(NestedOrPartOfAttributePredicate nestedOrPartOfAttributePredicate)
public ValidatableService getValidatableService()
public void setValidatableService(ValidatableService validatableService)
public CMSItemValidator<ItemModel> getCmsItemValidatorCreate()
public void setCmsItemValidatorCreate(CMSItemValidator<ItemModel> cmsItemValidatorCreate)
public CMSItemValidator<ItemModel> getCmsItemValidatorUpdate()
public void setCmsItemValidatorUpdate(CMSItemValidator<ItemModel> cmsItemValidatorUpdate)
protected OriginalClonedItemProvider<ItemModel> getOriginalClonedItemProvider()
public void setOriginalClonedItemProvider(OriginalClonedItemProvider<ItemModel> originalClonedItemProvider)
protected ComponentCloningStrategy getComponentCloningStrategy()
public void setComponentCloningStrategy(ComponentCloningStrategy componentCloningStrategy)
protected CloneComponentContextProvider getCloneComponentContextProvider()
public void setCloneComponentContextProvider(CloneComponentContextProvider cloneComponentContextProvider)
protected AttributeStrategyConverterProvider getCloneAttributeStrategyConverter()
public void setCloneAttributeStrategyConverter(AttributeStrategyConverterProvider cloneAttributeStrategyConverter)
protected AttributeValueToRepresentationStrategy getAttributeValueToRepresentationStrategy()
public void setAttributeValueToRepresentationStrategy(AttributeValueToRepresentationStrategy attributeValueToRepresentationStrategy)
protected ComposedTypeToAttributeCollectionConverter getComposedTypeToAttributeCollectionConverter()
public void setComposedTypeToAttributeCollectionConverter(ComposedTypeToAttributeCollectionConverter composedTypeToAttributeCollectionConverter)
protected java.util.List<Populator<ItemModel,java.util.Map<java.lang.String,java.lang.Object>>> getCustomPopulators()
public void setCustomPopulators(java.util.List<Populator<ItemModel,java.util.Map<java.lang.String,java.lang.Object>>> customPopulators)
protected PermissionCRUDService getPermissionCRUDService()
public void setPermissionCRUDService(PermissionCRUDService permissionCRUDService)
protected CMSUserService getCmsUserService()
public void setCmsUserService(CMSUserService cmsUserService)
protected CMSPermissionChecker getCmsPermissionChecker()
public void setCmsPermissionChecker(CMSPermissionChecker cmsPermissionChecker)
protected java.util.function.Predicate<AttributeDescriptorModel> getIsCollectionPredicate()
public void setIsCollectionPredicate(java.util.function.Predicate<AttributeDescriptorModel> isCollectionPredicate)
Copyright © 2018 SAP SE. All Rights Reserved.