Class ItemModelConverter
- java.lang.Object
-
- de.hybris.platform.servicelayer.internal.converter.impl.ItemModelConverter
-
- All Implemented Interfaces:
TypeSystemAwareModelConverter
,UpdateableModelConverter
,ModelConverter
,java.lang.Cloneable
- Direct Known Subclasses:
PrefetchAllModelConverter
,VariantProductModelConverter
public class ItemModelConverter extends java.lang.Object implements java.lang.Cloneable, UpdateableModelConverter, TypeSystemAwareModelConverter
This is a generalModelConverter
implementation which should be working for almost everyAbstractItemModel
. Using theItemModelConverter(ModelService, I18NService, CommonI18NService, String, Class, SerializationStrategy, SourceTransformer, SelfHealingService)
constructor you specify which source Item class you want to use (e.g. Product, this will be used for compatibility checks inload(Object)
) and which ItemModel class will be created if you load such an item usingload(Object)
. If you need functionality which is beyond this simple implementation, you will have to provide your own ItemModel implementation. This class is an internal API and is subject to change without further notice
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
ItemModelConverter.AttributesToLoad
protected static class
ItemModelConverter.LoadedAttributeValues
static class
ItemModelConverter.ModelAttributeInfo
class
ItemModelConverter.ModifiedAttributeValues
static class
ItemModelConverter.RelationTypeAttributeInfo
static class
ItemModelConverter.TypeAttributeInfo
protected static class
ItemModelConverter.TypeMetaInfo
This class is an internal API and is subject to change without further notice
-
Constructor Summary
Constructors Constructor Description ItemModelConverter(ModelService modelService, I18NService i18nService, CommonI18NService commonI18NService, java.lang.String type, java.lang.Class<? extends AbstractItemModel> modelClass, SerializationStrategy serializationStrategy)
For backward compatibilityItemModelConverter(ModelService modelService, I18NService i18nService, CommonI18NService commonI18NService, java.lang.String type, java.lang.Class<? extends AbstractItemModel> modelClass, SerializationStrategy serializationStrategy, SourceTransformer sourceTransformer, SelfHealingService selfHealingService)
Constructs a newItemModelConverter
instance which handles beans of given class type related to given composed type.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addModelModificationListener(java.lang.Object model, ModelModificationListener listener)
Adds the givenModelModificationListener
to the given model.void
afterDetach(java.lang.Object model, ModelContext ctx)
This method is executed after the givenmodel
is attached from the givenModelContext
void
afterModification(AbstractItemModel model, PK pk, long persistenceVersion)
protected ItemModelConverter.TypeMetaInfo
assembleMetaInfo(ComposedType ct, java.util.Collection<ItemModelConverter.TypeAttributeInfo> attributes)
InitializesItemModelConverter.TypeMetaInfo._modelAttributesAll
andItemModelConverter.TypeMetaInfo._modelAttributesInitial
using attribute meta infos.void
beforeAttach(java.lang.Object model, ModelContext ctx)
This method is executed before the givenmodel
is attached to the givenModelContext
protected java.util.Collection<ItemModelConverter.TypeAttributeInfo>
calculateTypeAttributeInfos(ComposedType ct)
Calculates attribute meta info objects for a given composed type.protected void
clearAttribute(AbstractItemModel model, java.lang.String qualifier)
protected void
clearLocAttribute(AbstractItemModel model, java.lang.String qualifier, java.util.Locale loc)
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.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.AbstractItemModel
create(java.lang.String type)
Instantiates a new instance of configured model class.protected ItemModelInternalContext
createContextForExistingModel(java.lang.String type, PK pk, long persistenceVersion, AttributeProvider attributeProvider)
protected ItemModelInternalContext
createContextForNewModel(java.lang.String type)
protected ItemModelConverter.ModelAttributeInfo
createModelAttributeInfo(ItemModelConverter.TypeAttributeInfo info)
This method is an internal API and is subject to change without further noticeprotected AbstractItemModel
createModelInstance(ItemModelInternalContext ctx)
protected PersistenceObject
createNewItem(AbstractItemModel model, ItemModelConverter.ModifiedAttributeValues values)
Performs item creation.boolean
equals(java.lang.Object o)
boolean
exists(java.lang.Object model)
Returnstrue
if for the given model a source Item exists and if this item Item#isAlive()protected void
fillModel(AbstractItemModel model, ItemModelConverter.AttributesToLoad attributesToLoad, PersistenceObject item)
Loads and fills model instance with loaded attribute values.java.util.List<ItemModelConverter.ModelAttributeInfo>
getAllModelAttributes()
protected ItemModelConverter.AttributesToLoad
getAttributesToReload(AbstractItemModel model, ItemModelConverter.ModifiedAttributeValues savedValues, boolean forCreation)
java.lang.Object
getAttributeValue(java.lang.Object model, java.lang.String attributeQualifier)
Generic attribute value getter to read attribute data from arbitrary model instances.protected CommonI18NService
getCommonI18NService()
protected ComposedType
getComposedType(AbstractItemModel model)
protected ConfigIntf
getConfig()
Encapsulates fetching ofConfigIntf
.java.lang.String
getDefaultType()
java.util.Map<java.lang.String,java.util.Set<java.util.Locale>>
getDirtyAttributes(java.lang.Object model)
Returns a map with all modified attribute qualifiers for the given model.java.lang.Object
getDirtyAttributeValue(java.lang.Object model, java.lang.String attributeQualifier)
Internal method forDefaultModelService
when inspecting dirty attributes during save!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)
java.lang.Object
getDirtyLocalizedAttributeValue(java.lang.Object model, java.lang.String attributeQualifier, java.util.Locale locale)
Internal method forDefaultModelService
when inspecting dirty attributes during save!protected DynamicAttributesProvider
getDynamicAttributesProvider()
protected java.util.Set<ItemModelConverter.ModelAttributeInfo>
getExcluded(java.util.Collection<java.lang.String> excluded)
protected java.lang.Object
getFieldValue(java.lang.Object model, ItemModelConverter.ModelAttributeInfo info)
protected java.lang.reflect.Method
getGetter(java.lang.Object model, ItemModelConverter.ModelAttributeInfo info)
protected I18NService
getI18nService()
ItemModelConverter.ModelAttributeInfo
getInfo(java.lang.String qualfier)
java.util.List<ItemModelConverter.ModelAttributeInfo>
getInitialModelAttributes()
protected LocaleProvider
getLocaleProvider()
java.lang.Object
getLocalizedAttributeValue(java.lang.Object model, java.lang.String attributeQualifier, java.util.Locale locale)
Generic attribute value getter to read attribute data from arbitrary model instances.protected java.lang.reflect.Method
getLocalizedGetter(java.lang.Object model, ItemModelConverter.ModelAttributeInfo info)
protected java.lang.reflect.Method
getLocalizedSetter(java.lang.Object model, ItemModelConverter.ModelAttributeInfo info, java.lang.Object value)
java.util.Set<java.lang.String>
getMandatoryAttributes()
java.util.Set<java.lang.String>
getMandatoryAttributesForCreation()
java.lang.Class<? extends AbstractItemModel>
getModelClass()
Gets the class used for instantiation of related models.protected ModelService
getModelService()
java.util.Set<java.lang.String>
getPartOfAttributes(TypeService typeService)
Returns a collection of all partof atrributesPersistenceObject
getPersistenceSource(java.lang.Object model)
SerializationStrategy
getSerializationStrategy()
protected java.lang.reflect.Method
getSetter(java.lang.Object model, ItemModelConverter.ModelAttributeInfo info, java.lang.Object value)
java.lang.Object
getSource(java.lang.Object model)
Deprecated.since 5.7.0 - Please usegetPersistenceSource(Object)
protected java.util.Locale
getStdLocale()
java.lang.String
getType(java.lang.Object model)
Returns the exact type of the given model.protected java.lang.String
getTypeFromModelContext(java.lang.Object model)
java.util.Set<java.lang.String>
getUniqueAttributes()
java.util.Set<java.lang.String>
getWritablePartOfAttributes(TypeService typeService)
Returns a collection of writable partof atrributesint
hashCode()
protected boolean
hasNonDataLocales(java.util.Map<java.util.Locale,java.util.Set<java.util.Locale>> dataLocale2LocaleMappings)
void
init(ConverterRegistry registry)
Called once before using the converter the first time.boolean
isConfiguredForLegacyPersistence()
protected boolean
isEnumValue(java.lang.Object value)
boolean
isModified(java.lang.Object model)
Returnstrue
if the given model is new or the ModelValueHistory of the model contains changed attributes.boolean
isModified(java.lang.Object model, java.lang.String attribute)
Returnstrue
if the given model is new or the ModelValueHistory for the given attribute (qualifier) was changed.boolean
isModified(java.lang.Object model, java.lang.String attribute, java.util.Locale loc)
Returnstrue
if the given model is new or the ModelValueHistory for the given attribute (qualifier) was changed.boolean
isNew(java.lang.Object model)
Returnstrue
if the given model was not persisted yet.protected boolean
isNonLazyLoadedAttribute(AttributeDescriptor desc)
Tells whether or not a attribute should be lazy loaded.protected boolean
isReferenceAttribute(AttributeDescriptor desc)
Tells whether an attribute is a reference to an item (including Collection and Maps referencing items).boolean
isRemoved(java.lang.Object model)
Returnstrue
if for the given model no source Item exists or this item is not Item#isAlive()boolean
isUpToDate(java.lang.Object model)
The given model is not up-to-date (returnsfalse
) when: the model is new (seeModelConverter.isNew(Object)
) or the model was removed (seeModelConverter.isRemoved(Object)
) or the model was locally modified or the Item in the database is newer as the source item of the modelboolean
jaloOnlyAttribute(java.lang.String qualifier)
AbstractItemModel
load(java.lang.Object source)
Instantiates a new instance of configured model class for the given sourceItem
and loads all of its attributes.protected void
mergeNonDataLocales(AbstractItemModel model)
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)
protected boolean
mustConvert(Type type)
Tells whether or not values of the given type require conversion before using them as model attribute values.protected void
preLoadAttribute(AbstractItemModel model, java.lang.String qualifier, java.lang.Object value)
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)
protected ItemModelConverter.LoadedAttributeValues
readAttributes(java.util.Locale dataLoc, PersistenceObject item, java.util.Set<java.lang.String> qualifiers)
Performs bulk-reading of item attribute values,protected AttributePrefetchMode
readPrefetchSettings()
Reads configuration settingServicelayerConstants.PARAM_PREFETCH
and determines preFetch mode.protected java.lang.Object
readSingleAttribute(java.util.Locale dataLoc, PersistenceObject item, java.lang.String qualifier)
Performs reading for a single item attribute.void
reload(java.lang.Object modelOriginal)
Clears all attributes of given bean so that they will be reloaded on next request.void
remove(java.lang.Object model)
Tries to remove the sourceItem
of the givenAbstractItemModel
.void
removeModelModificationListener(java.lang.Object model, ModelModificationListener listener)
Removes the ModelModificationListener from the given model.void
save(java.lang.Object model, java.util.Collection<java.lang.String> excludedAttributes)
Takes all modified values from the givenAbstractItemModel
and writes them down to the source Item (if it exists).protected void
setAttributeLoadError(AbstractItemModel model, java.lang.String qualifier, ModelLoadingException error)
void
setAttributeValue(java.lang.Object model, java.lang.String attributeQualifier, java.lang.Object value)
Generic attribute value setter to modify attribute data on arbitrary model instances.protected void
setLocAttributeLoadError(AbstractItemModel model, java.lang.String qualifier, java.util.Locale loc, ModelLoadingException error)
protected void
storeAttributes(Item item, ItemModelConverter.ModifiedAttributeValues values)
Performs storing of item attribute values.java.lang.String
toString()
void
typeSystemChanged()
Type system was changed and converter will respect this changes.void
unloadAttributes(AbstractItemModel model)
-
-
-
Constructor Detail
-
ItemModelConverter
public ItemModelConverter(ModelService modelService, I18NService i18nService, CommonI18NService commonI18NService, java.lang.String type, java.lang.Class<? extends AbstractItemModel> modelClass, SerializationStrategy serializationStrategy)
For backward compatibility
-
ItemModelConverter
public ItemModelConverter(ModelService modelService, I18NService i18nService, CommonI18NService commonI18NService, java.lang.String type, java.lang.Class<? extends AbstractItemModel> modelClass, SerializationStrategy serializationStrategy, SourceTransformer sourceTransformer, SelfHealingService selfHealingService)
Constructs a newItemModelConverter
instance which handles beans of given class type related to given composed type.- Parameters:
type
- specifies the type this handler can handle, is used insave(Object, Collection)
if a new item instance is createdmodelClass
- specifies whichAbstractItemModel
class will be used to instantiate a new model viaload(Object)
-
-
Method Detail
-
readPrefetchSettings
protected AttributePrefetchMode readPrefetchSettings()
Reads configuration settingServicelayerConstants.PARAM_PREFETCH
and determines preFetch mode. Method is called once initially for eachItemModelConverter
instance.ServicelayerConstants.VALUE_PREFETCH_DEFAULT
or no value means
-
getConfig
protected ConfigIntf getConfig()
Encapsulates fetching ofConfigIntf
. This allows overriding e.g. for test cases.
-
getInitialModelAttributes
public java.util.List<ItemModelConverter.ModelAttributeInfo> getInitialModelAttributes()
-
getAllModelAttributes
public java.util.List<ItemModelConverter.ModelAttributeInfo> getAllModelAttributes()
-
getInfo
public ItemModelConverter.ModelAttributeInfo getInfo(java.lang.String qualfier)
-
create
public AbstractItemModel create(java.lang.String type)
Instantiates a new instance of configured model class.- Specified by:
create
in interfaceModelConverter
- Returns:
- new empty model
-
isConfiguredForLegacyPersistence
public boolean isConfiguredForLegacyPersistence()
-
createModelInstance
protected AbstractItemModel createModelInstance(ItemModelInternalContext ctx)
-
createContextForNewModel
protected ItemModelInternalContext createContextForNewModel(java.lang.String type)
-
createContextForExistingModel
protected ItemModelInternalContext createContextForExistingModel(java.lang.String type, PK pk, long persistenceVersion, AttributeProvider attributeProvider)
-
load
public final AbstractItemModel load(java.lang.Object source)
Instantiates a new instance of configured model class for the given sourceItem
and loads all of its attributes.- Specified by:
load
in interfaceModelConverter
- 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.
-
addModelModificationListener
public void addModelModificationListener(java.lang.Object model, ModelModificationListener listener)
Description copied from interface:UpdateableModelConverter
Adds the givenModelModificationListener
to the given model.- Specified by:
addModelModificationListener
in interfaceUpdateableModelConverter
-
removeModelModificationListener
public void removeModelModificationListener(java.lang.Object model, ModelModificationListener listener)
Description copied from interface:UpdateableModelConverter
Removes the ModelModificationListener from the given model.- Specified by:
removeModelModificationListener
in interfaceUpdateableModelConverter
-
beforeAttach
public void beforeAttach(java.lang.Object model, ModelContext ctx)
Description copied from interface:ModelConverter
This method is executed before the givenmodel
is attached to the givenModelContext
- Specified by:
beforeAttach
in interfaceModelConverter
-
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)
-
afterDetach
public void afterDetach(java.lang.Object model, ModelContext ctx)
Description copied from interface:ModelConverter
This method is executed after the givenmodel
is attached from the givenModelContext
- Specified by:
afterDetach
in interfaceModelConverter
-
getWritablePartOfAttributes
public java.util.Set<java.lang.String> getWritablePartOfAttributes(TypeService typeService)
Description copied from interface:ModelConverter
Returns a collection of writable partof atrributes- Specified by:
getWritablePartOfAttributes
in interfaceModelConverter
-
getPartOfAttributes
public java.util.Set<java.lang.String> getPartOfAttributes(TypeService typeService)
Description copied from interface:ModelConverter
Returns a collection of all partof atrributes- Specified by:
getPartOfAttributes
in interfaceModelConverter
-
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 interfaceModelConverter
- Parameters:
modelOriginal
- model which will be filled from scratch using mapped source
-
remove
public void remove(java.lang.Object model)
Tries to remove the sourceItem
of the givenAbstractItemModel
.- Specified by:
remove
in interfaceModelConverter
- 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 givenAbstractItemModel
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 interfaceModelConverter
- Parameters:
model
- the model to save- Throws:
java.lang.IllegalArgumentException
- if the given model is not an instance of ItemModeljava.lang.IllegalStateException
- if the source item of the model doesn't exist any more
-
afterModification
public void afterModification(AbstractItemModel model, PK pk, long persistenceVersion)
-
unloadAttributes
public void unloadAttributes(AbstractItemModel model)
-
getExcluded
protected java.util.Set<ItemModelConverter.ModelAttributeInfo> getExcluded(java.util.Collection<java.lang.String> excluded)
-
getSource
@Deprecated public java.lang.Object getSource(java.lang.Object model)
Deprecated.since 5.7.0 - Please usegetPersistenceSource(Object)
For the given bean the underlyingItem
is returned.- Specified by:
getSource
in interfaceModelConverter
- 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 typeAbstractItemModel
java.lang.IllegalStateException
- is the model has never been persisted or the underlying item does not exist any more
-
getPersistenceSource
public PersistenceObject getPersistenceSource(java.lang.Object model)
- Specified by:
getPersistenceSource
in interfaceModelConverter
-
isModified
public boolean isModified(java.lang.Object model)
Description copied from interface:ModelConverter
Returnstrue
if the given model is new or the ModelValueHistory of the model contains changed attributes.- Specified by:
isModified
in interfaceModelConverter
- Parameters:
model
- the model- Returns:
false
otherwise
-
isModified
public boolean isModified(java.lang.Object model, java.lang.String attribute)
Description copied from interface:ModelConverter
Returnstrue
if the given model is new or the ModelValueHistory for the given attribute (qualifier) was changed. If the attribute is localized the current session dataLocale
(see LocaleProvider#getCurrentDataLocale()) is used.- Specified by:
isModified
in interfaceModelConverter
- Parameters:
model
- the modelattribute
- 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
Returnstrue
if the given model is new or the ModelValueHistory for the given attribute (qualifier) was changed. For localized attributes the givenLocale
is used to check for modifications. If the Locale isnull
then all Locales will be checked for modifications. For non-localized attributes the given Locale will be ignored.- Specified by:
isModified
in interfaceModelConverter
- Parameters:
model
- the modelattribute
- the attribute qualifierloc
- the Locale. Can benull
.- Returns:
false
otherwise.
-
exists
public boolean exists(java.lang.Object model)
Description copied from interface:ModelConverter
Returnstrue
if for the given model a source Item exists and if this item Item#isAlive()- Specified by:
exists
in interfaceModelConverter
- 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
Returnstrue
if for the given model no source Item exists or this item is not Item#isAlive()- Specified by:
isRemoved
in interfaceModelConverter
- Parameters:
model
- the model- Returns:
false
if the modelModelConverter.isNew(Object)
or the item is alive.
-
isNew
public boolean isNew(java.lang.Object model)
Description copied from interface:ModelConverter
Returnstrue
if the given model was not persisted yet.- Specified by:
isNew
in interfaceModelConverter
- 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 (returnsfalse
) when:- the model is new (see
ModelConverter.isNew(Object)
) or - the model was removed (see
ModelConverter.isRemoved(Object)
) or - the model was locally modified or
- the Item in the database is newer as the source item of the model
- Specified by:
isUpToDate
in interfaceModelConverter
- Parameters:
model
- the model- Returns:
true
if the model is up-to-date
- the model is new (see
-
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 interfaceModelConverter
- Parameters:
model
- the model instanceattributeQualifier
- the attribute qualifier- Returns:
- the attribute value
-
getDirtyAttributeValue
public java.lang.Object getDirtyAttributeValue(java.lang.Object model, java.lang.String attributeQualifier)
Internal method forDefaultModelService
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 interfaceModelConverter
- Parameters:
model
- the model instanceattributeQualifier
- the attribute qualifierlocale
- 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 forDefaultModelService
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 interfaceModelConverter
- Parameters:
model
- the modelattributeQualifier
- the attribute qualifiervalue
- 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 interfaceModelConverter
-
getTypeFromModelContext
protected java.lang.String getTypeFromModelContext(java.lang.Object model)
-
getComposedType
protected ComposedType getComposedType(AbstractItemModel 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 useditem
- the item to read fromqualifier
- the attribute qualifier- Returns:
- the attribute value
-
jaloOnlyAttribute
public boolean jaloOnlyAttribute(java.lang.String qualifier)
-
calculateTypeAttributeInfos
protected java.util.Collection<ItemModelConverter.TypeAttributeInfo> calculateTypeAttributeInfos(ComposedType ct)
Calculates attribute meta info objects for a given composed type.
-
isReferenceAttribute
protected boolean isReferenceAttribute(AttributeDescriptor desc)
Tells whether an attribute is a reference to an item (including Collection and Maps referencing items).
-
assembleMetaInfo
protected ItemModelConverter.TypeMetaInfo assembleMetaInfo(ComposedType ct, java.util.Collection<ItemModelConverter.TypeAttributeInfo> attributes)
InitializesItemModelConverter.TypeMetaInfo._modelAttributesAll
andItemModelConverter.TypeMetaInfo._modelAttributesInitial
using attribute meta infos. Must be called with active write lock!!
-
createModelAttributeInfo
protected ItemModelConverter.ModelAttributeInfo createModelAttributeInfo(ItemModelConverter.TypeAttributeInfo info)
This method is an internal API and is subject to change without further notice
-
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 fromqualifiers
- 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 intovalues
- 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()
-
createNewItem
protected PersistenceObject createNewItem(AbstractItemModel model, ItemModelConverter.ModifiedAttributeValues values)
Performs item creation. Override this method if you have to provide sophisticated functionality to create a new Item (more than justComposedType.newInstance(Map)
.- Parameters:
values
- the attributes for the new item- Returns:
- the new Item instance
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
fillModel
protected void fillModel(AbstractItemModel model, ItemModelConverter.AttributesToLoad attributesToLoad, PersistenceObject item)
Loads and fills model instance with loaded attribute values.- Parameters:
model
- the model instance to fill values intoattributesToLoad
- the attributes to be loaded
-
setLocAttributeLoadError
protected void setLocAttributeLoadError(AbstractItemModel model, java.lang.String qualifier, java.util.Locale loc, ModelLoadingException error)
-
setAttributeLoadError
protected void setAttributeLoadError(AbstractItemModel model, java.lang.String qualifier, ModelLoadingException error)
-
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)
-
getAttributesToReload
protected ItemModelConverter.AttributesToLoad getAttributesToReload(AbstractItemModel model, ItemModelConverter.ModifiedAttributeValues savedValues, boolean forCreation)
-
init
public void init(ConverterRegistry registry)
Description copied from interface:ModelConverter
Called once before using the converter the first time.- Specified by:
init
in interfaceModelConverter
- Parameters:
registry
- the registry holding this converter.
-
getModelService
protected ModelService getModelService()
-
getI18nService
protected I18NService getI18nService()
-
getCommonI18NService
protected CommonI18NService getCommonI18NService()
-
getLocaleProvider
protected LocaleProvider getLocaleProvider()
-
getDynamicAttributesProvider
protected DynamicAttributesProvider getDynamicAttributesProvider()
-
getGetter
protected java.lang.reflect.Method getGetter(java.lang.Object model, ItemModelConverter.ModelAttributeInfo info)
-
getLocalizedGetter
protected java.lang.reflect.Method getLocalizedGetter(java.lang.Object model, ItemModelConverter.ModelAttributeInfo info)
-
getSetter
protected java.lang.reflect.Method getSetter(java.lang.Object model, ItemModelConverter.ModelAttributeInfo info, java.lang.Object value)
-
getLocalizedSetter
protected java.lang.reflect.Method getLocalizedSetter(java.lang.Object model, ItemModelConverter.ModelAttributeInfo info, java.lang.Object value)
-
getSerializationStrategy
public SerializationStrategy getSerializationStrategy()
-
getFieldValue
protected final java.lang.Object getFieldValue(java.lang.Object model, ItemModelConverter.ModelAttributeInfo info)
-
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 isnull
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 interfaceModelConverter
- 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()
-
typeSystemChanged
public void typeSystemChanged()
Description copied from interface:TypeSystemAwareModelConverter
Type system was changed and converter will respect this changes.- Specified by:
typeSystemChanged
in interfaceTypeSystemAwareModelConverter
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-