Class CMSVersionToItemModelPopulator

    • Constructor Detail

      • CMSVersionToItemModelPopulator

        public CMSVersionToItemModelPopulator()
    • Method Detail

      • populate

        public void populate​(AuditPayload auditPayload,
                             ItemModel itemModel)
        Description copied from interface: Populator
        Populate the target instance with values from the source instance.
        Specified by:
        populate in interface Populator<AuditPayload,​ItemModel>
        Parameters:
        auditPayload - the source object
        itemModel - 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 from AuditPayload to attribute values of ItemModel
        Parameters:
        values - the list of attributes from AuditPayload
        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 from AuditPayload to attribute values of ItemModel
        Parameters:
        values - the list of localized attributes from AuditPayload
        Returns:
        the list of localized attributes applicable for ItemModel
      • getAttributeValueMapperForTypedValue

        protected java.util.function.Function<TypedValue,​java.util.Optional<java.lang.Object>> getAttributeValueMapperForTypedValue()
        Returns a Function aimed at converting any non localized value described by a TypedValue.
        Returns:
        a Function to convert a non localized value.
      • getAttributeValueMapperForLocalizedTypedValue

        protected java.util.function.Function<LocalizedTypedValue,​java.util.Optional<java.lang.Object>> getAttributeValueMapperForLocalizedTypedValue()
        Returns a Function aimed at converting any localized value described by a LocalizedTypedValue.
        Returns:
        the Function to 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 a Map of Locale and Object.
        Parameters:
        localizedTypedValue - the LocalizedTypedValue value.
        localizedValueConverter - the Function that converts the list of String values to Object.
        Returns:
        the Map that contains localized values.
      • convertCollectionValue

        protected java.util.function.Function<java.util.List<java.lang.String>,​java.lang.Object> convertCollectionValue​(ValueType valueType)
        Returns the Function that converts a collection of String values to Object.
        Parameters:
        valueType - the ValueType describing 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 the Function that converts a collection containing one String element to Object.
        Parameters:
        valueType - the ValueType describing 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 to ItemModel.
        Parameters:
        itemModel - the ItemModel to apply the attribute values.
        values - the Map of attribute values.
      • getEmptyCollectionValuesPerQualifier

        protected java.util.Map<java.lang.String,​java.lang.Object> getEmptyCollectionValuesPerQualifier​(ItemModel itemModel,
                                                                                                              AuditPayload auditPayload)
        Returns the Map that contains default (empty) collection values for every collection attribute that is null.
        Parameters:
        itemModel - the ItemModel to verify attributes on.
        Returns:
        the Map.
      • collectStreamResult

        protected java.util.Collection<java.lang.Object> collectStreamResult​(ValueType valueType,
                                                                             java.util.stream.Stream<java.lang.Object> stream)
        Applies a proper Collector to a stream using ValueType.
        Parameters:
        valueType - the ValueType that is used to extract the collection type of a payload's attribute.
        stream - the Stream to 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 a Function aimed at converting any value described by a ValueType. This function will execute one of the provided suppliers depending on whether the value is a collection or not.
        Parameters:
        collectionGetter - a Supplier invoked if the ValueType is a collection
        simpleGetter - a Supplier invoked if the ValueType is not a collection
        Returns:
        a Function to convert a value
      • convertCustomAttributesValues

        protected void convertCustomAttributesValues​(ItemModel itemModel,
                                                     java.util.Map<java.lang.String,​TypedValue> values)
        Converts custom attribute values that are represented by CMSVersionCustomAttribute.
        Parameters:
        itemModel - the ItemModel to which the custom attributes are applied.
        values - the list of non localized attributes from the payload.
      • isCustomAttributeDataType

        protected boolean isCustomAttributeDataType​(java.lang.String payloadType)
        Verifies whether the payloadType represents the CMSVersionCustomAttribute or 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 the ValueType from payload represents a collection or not.
        Parameters:
        valueType - the ValueType.
        Returns:
        true if ValueType represents a collection, false otherwise.
      • setCollectionHelper

        public void setCollectionHelper​(CollectionHelper collectionHelper)
      • setCmsVersionHelper

        public void setCmsVersionHelper​(CMSVersionHelper cmsVersionHelper)
      • setCommonI18NService

        public void setCommonI18NService​(CommonI18NService commonI18NService)
      • getModelService

        protected ModelService getModelService()
      • setModelService

        public void setModelService​(ModelService modelService)
      • getIsCollectionPredicate

        protected java.util.function.Predicate<AttributeDescriptorModel> getIsCollectionPredicate()
      • setIsCollectionPredicate

        public void setIsCollectionPredicate​(java.util.function.Predicate<AttributeDescriptorModel> isCollectionPredicate)