Class ItemModelConverter

    • Method Detail

      • getConfig

        protected ConfigIntf getConfig()
        Encapsulates fetching of ConfigIntf. This allows overriding e.g. for test cases.
      • create

        public AbstractItemModel create​(java.lang.String type)
        Instantiates a new instance of configured model class.
        Specified by:
        create in interface ModelConverter
        Returns:
        new empty model
      • isConfiguredForLegacyPersistence

        public boolean isConfiguredForLegacyPersistence()
      • load

        public final AbstractItemModel load​(java.lang.Object source)
        Instantiates a new instance of configured model class for the given source Item and loads all of its attributes.
        Specified by:
        load in interface ModelConverter
        Parameters:
        source - object which will be used for filling new model
        Returns:
        new model instance with data of given source
        Throws:
        java.lang.IllegalArgumentException - if the given source object is not compatible with the item class provided in this classes constructor.
      • mergeNonDataLocales

        protected void mergeNonDataLocales​(AbstractItemModel model)
      • mergeOldValuesIntoDataLocales

        public LocMap<java.util.Locale,​java.lang.Object> mergeOldValuesIntoDataLocales​(java.util.Map<java.util.Locale,​java.util.Set<java.util.Locale>> dataLocale2LocaleMappings,
                                                                                             java.lang.String qualifier,
                                                                                             LocMap<java.util.Locale,​java.lang.Object> oldLocValues)
      • getDirtyLocalizedAttributesWithNonDataLocales

        protected java.util.Set<java.lang.String> getDirtyLocalizedAttributesWithNonDataLocales​(java.util.Map<java.util.Locale,​java.util.Set<java.lang.String>> dirtyLocalizedAttributes,
                                                                                                java.util.Map<java.util.Locale,​java.util.Set<java.util.Locale>> dataLocale2NonDataLocales)
      • hasNonDataLocales

        protected boolean hasNonDataLocales​(java.util.Map<java.util.Locale,​java.util.Set<java.util.Locale>> dataLocale2LocaleMappings)
      • reload

        public void reload​(java.lang.Object modelOriginal)
        Clears all attributes of given bean so that they will be reloaded on next request.
        Specified by:
        reload in interface ModelConverter
        Parameters:
        modelOriginal - model which will be filled from scratch using mapped source
      • remove

        public void remove​(java.lang.Object model)
        Tries to remove the source Item of the given AbstractItemModel.
        Specified by:
        remove in interface ModelConverter
        Parameters:
        model - the model for which to remove the source
        Throws:
        java.lang.IllegalArgumentException - if the given model is not of type ItemModel
      • save

        public void save​(java.lang.Object model,
                         java.util.Collection<java.lang.String> excludedAttributes)
        Takes all modified values from the given AbstractItemModel and writes them down to the source Item (if it exists). If the item doesn't exist, an exception is thrown since the Item type itself is abstract.
        Specified by:
        save in interface ModelConverter
        Parameters:
        model - the model to save
        Throws:
        java.lang.IllegalArgumentException - if the given model is not an instance of ItemModel
        java.lang.IllegalStateException - if the source item of the model doesn't exist any more
      • afterModification

        public void afterModification​(AbstractItemModel model,
                                      PK pk,
                                      long persistenceVersion)
      • getSource

        @Deprecated
        public java.lang.Object getSource​(java.lang.Object model)
        Deprecated.
        since 5.7.0 - Please usegetPersistenceSource(Object)
        For the given bean the underlying Item is returned.
        Specified by:
        getSource in interface ModelConverter
        Parameters:
        model - the model for which to return the source
        Returns:
        the underlying source of the given model, or null if the source doesn't (yet) exist
        Throws:
        java.lang.IllegalArgumentException - if the given bean is not of type AbstractItemModel
        java.lang.IllegalStateException - is the model has never been persisted or the underlying item does not exist any more
      • isModified

        public boolean isModified​(java.lang.Object model)
        Description copied from interface: ModelConverter
        Returns true if the given model is new or the ModelValueHistory of the model contains changed attributes.
        Specified by:
        isModified in interface ModelConverter
        Parameters:
        model - the model
        Returns:
        false otherwise
      • isModified

        public boolean isModified​(java.lang.Object model,
                                  java.lang.String attribute)
        Description copied from interface: ModelConverter
        Returns true if the given model is new or the ModelValueHistory for the given attribute (qualifier) was changed. If the attribute is localized the current session data Locale (see LocaleProvider#getCurrentDataLocale()) is used.
        Specified by:
        isModified in interface ModelConverter
        Parameters:
        model - the model
        attribute - the attribute qualifier
        Returns:
        false if the attribute was not modified.
      • isModified

        public boolean isModified​(java.lang.Object model,
                                  java.lang.String attribute,
                                  java.util.Locale loc)
        Description copied from interface: ModelConverter
        Returns true if the given model is new or the ModelValueHistory for the given attribute (qualifier) was changed. For localized attributes the given Locale is used to check for modifications. If the Locale is null then all Locales will be checked for modifications. For non-localized attributes the given Locale will be ignored.
        Specified by:
        isModified in interface ModelConverter
        Parameters:
        model - the model
        attribute - the attribute qualifier
        loc - the Locale. Can be null.
        Returns:
        false otherwise.
      • exists

        public boolean exists​(java.lang.Object model)
        Description copied from interface: ModelConverter
        Returns true if for the given model a source Item exists and if this item Item#isAlive()
        Specified by:
        exists in interface ModelConverter
        Parameters:
        model - the model
        Returns:
        false if the model was not persisted yet (no underlying item) or the item was removed.
      • isRemoved

        public boolean isRemoved​(java.lang.Object model)
        Description copied from interface: ModelConverter
        Returns true if for the given model no source Item exists or this item is not Item#isAlive()
        Specified by:
        isRemoved in interface ModelConverter
        Parameters:
        model - the model
        Returns:
        false if the model ModelConverter.isNew(Object) or the item is alive.
      • isNew

        public boolean isNew​(java.lang.Object model)
        Description copied from interface: ModelConverter
        Returns true if the given model was not persisted yet.
        Specified by:
        isNew in interface ModelConverter
        Parameters:
        model - the model
        Returns:
        false if an AttributeProvider for the given model exists.
      • isUpToDate

        public boolean isUpToDate​(java.lang.Object model)
        Description copied from interface: ModelConverter
        The given model is not up-to-date (returns false) when:
        Specified by:
        isUpToDate in interface ModelConverter
        Parameters:
        model - the model
        Returns:
        true if the model is up-to-date
      • getAttributeValue

        public java.lang.Object getAttributeValue​(java.lang.Object model,
                                                  java.lang.String attributeQualifier)
        Description copied from interface: ModelConverter
        Generic attribute value getter to read attribute data from arbitrary model instances.
        Specified by:
        getAttributeValue in interface ModelConverter
        Parameters:
        model - the model instance
        attributeQualifier - the attribute qualifier
        Returns:
        the attribute value
      • getDirtyAttributeValue

        public java.lang.Object getDirtyAttributeValue​(java.lang.Object model,
                                                       java.lang.String attributeQualifier)
        Internal method for DefaultModelService when inspecting dirty attributes during save!
      • getLocalizedAttributeValue

        public java.lang.Object getLocalizedAttributeValue​(java.lang.Object model,
                                                           java.lang.String attributeQualifier,
                                                           java.util.Locale locale)
        Description copied from interface: ModelConverter
        Generic attribute value getter to read attribute data from arbitrary model instances.
        Specified by:
        getLocalizedAttributeValue in interface ModelConverter
        Parameters:
        model - the model instance
        attributeQualifier - the attribute qualifier
        locale - Locale for which value will be returned
        Returns:
        the attribute value
      • getDirtyLocalizedAttributeValue

        public java.lang.Object getDirtyLocalizedAttributeValue​(java.lang.Object model,
                                                                java.lang.String attributeQualifier,
                                                                java.util.Locale locale)
        Internal method for DefaultModelService when inspecting dirty attributes during save!
      • setAttributeValue

        public void setAttributeValue​(java.lang.Object model,
                                      java.lang.String attributeQualifier,
                                      java.lang.Object value)
        Description copied from interface: ModelConverter
        Generic attribute value setter to modify attribute data on arbitrary model instances.
        Specified by:
        setAttributeValue in interface ModelConverter
        Parameters:
        model - the model
        attributeQualifier - the attribute qualifier
        value - the attribute value
      • getModelClass

        public java.lang.Class<? extends AbstractItemModel> getModelClass()
        Gets the class used for instantiation of related models.
        Returns:
        model class
      • getDefaultType

        public java.lang.String getDefaultType()
      • getType

        public java.lang.String getType​(java.lang.Object model)
        Description copied from interface: ModelConverter
        Returns the exact type of the given model.
        Specified by:
        getType in interface ModelConverter
      • getTypeFromModelContext

        protected java.lang.String getTypeFromModelContext​(java.lang.Object model)
      • readSingleAttribute

        protected java.lang.Object readSingleAttribute​(java.util.Locale dataLoc,
                                                       PersistenceObject item,
                                                       java.lang.String qualifier)
        Performs reading for a single item attribute.
        Parameters:
        dataLoc - the locale to be used
        item - the item to read from
        qualifier - the attribute qualifier
        Returns:
        the attribute value
      • jaloOnlyAttribute

        public boolean jaloOnlyAttribute​(java.lang.String qualifier)
      • isReferenceAttribute

        protected boolean isReferenceAttribute​(AttributeDescriptor desc)
        Tells whether an attribute is a reference to an item (including Collection and Maps referencing items).
      • readAttributes

        protected ItemModelConverter.LoadedAttributeValues readAttributes​(java.util.Locale dataLoc,
                                                                          PersistenceObject item,
                                                                          java.util.Set<java.lang.String> qualifiers)
        Performs bulk-reading of item attribute values,
        Parameters:
        item - the item to read from
        qualifiers - the attributes to load values for
      • storeAttributes

        protected void storeAttributes​(Item item,
                                       ItemModelConverter.ModifiedAttributeValues values)
        Performs storing of item attribute values.
        Parameters:
        item - the item to write into
        values - the (jalo compatible!) values to store
      • isNonLazyLoadedAttribute

        protected boolean isNonLazyLoadedAttribute​(AttributeDescriptor desc)
        Tells whether or not a attribute should be lazy loaded.
        Parameters:
        desc - the attribute descriptor
      • mustConvert

        protected boolean mustConvert​(Type type)
        Tells whether or not values of the given type require conversion before using them as model attribute values. Here all instances of composed types and other types containing composed types are considered to require conversion.
        Parameters:
        type - the type to check
        See Also:
        isNonLazyLoadedAttribute(AttributeDescriptor)
      • getStdLocale

        protected java.util.Locale getStdLocale()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • preLoadLocAttribute

        protected void preLoadLocAttribute​(java.util.Map<java.lang.String,​LocMap<java.util.Locale,​java.lang.Object>> localizedAttributesFieldValue,
                                           AbstractItemModel model,
                                           java.lang.String qualifier,
                                           java.util.Locale loc,
                                           java.lang.Object value)
      • clearLocAttribute

        protected void clearLocAttribute​(AbstractItemModel model,
                                         java.lang.String qualifier,
                                         java.util.Locale loc)
      • preLoadAttribute

        protected void preLoadAttribute​(AbstractItemModel model,
                                        java.lang.String qualifier,
                                        java.lang.Object value)
      • clearAttribute

        protected void clearAttribute​(AbstractItemModel model,
                                      java.lang.String qualifier)
      • convertModelsToObjects

        protected java.lang.Object convertModelsToObjects​(AbstractItemModel model,
                                                          java.lang.String qualifier,
                                                          java.lang.Object value)
        Checks if the given object is a model, a collection of models, or a map with models and tries to convert them to related source object.
        Parameters:
        value - model, collection of models or map of models to convert
        Returns:
        converted source object/s or original if no conversion is possible
      • convertObjectsToModels

        protected java.lang.Object convertObjectsToModels​(PersistenceObject item,
                                                          java.lang.String qualifier,
                                                          java.lang.Object value)
        Tries to convert given object, collection of objects or map of objects to related model instances.
        Parameters:
        value - object, collection of objects or map of objects to convert to model/s
        Returns:
        converted model or original if no conversion is possible
      • isEnumValue

        protected boolean isEnumValue​(java.lang.Object value)
      • init

        public void init​(ConverterRegistry registry)
        Description copied from interface: ModelConverter
        Called once before using the converter the first time.
        Specified by:
        init in interface ModelConverter
        Parameters:
        registry - the registry holding this converter.
      • getModelService

        protected ModelService getModelService()
      • getI18nService

        protected I18NService getI18nService()
      • getDirtyAttributes

        public java.util.Map<java.lang.String,​java.util.Set<java.util.Locale>> getDirtyAttributes​(java.lang.Object model)
        Description copied from interface: ModelConverter
        Returns a map with all modified attribute qualifiers for the given model. The keys are all localized and non-localized attribute qualifier which were modified. If the map value is null the key is a non-localized attribute qualifier else the map value contains the locale in which language the localized attribute was modified.
        Specified by:
        getDirtyAttributes in interface ModelConverter
        Parameters:
        model - the new (not saved) model
        Returns:
        a map with all modified attribute qualifier.
      • getUniqueAttributes

        public java.util.Set<java.lang.String> getUniqueAttributes()
      • getMandatoryAttributes

        public java.util.Set<java.lang.String> getMandatoryAttributes()
      • getMandatoryAttributesForCreation

        public java.util.Set<java.lang.String> getMandatoryAttributesForCreation()
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object