Interface ModelConverter
- All Known Subinterfaces:
TypeSystemAwareModelConverter,UpdateableModelConverter
- All Known Implementing Classes:
EnumValueModelConverter,ItemModelConverter,PrefetchAllModelConverter,VariantProductModelConverter
public interface ModelConverter
A
ModelConverter is responsible for creating and filling a model from an underlying persistence system like
the hybris layer, a database, web service.- Since:
- 4.0
-
Method Summary
Modifier and TypeMethodDescriptionvoidafterDetach(Object model, ModelContext ctx) This method is executed after the givenmodelis attached from the givenModelContextvoidbeforeAttach(Object model, ModelContext ctx) This method is executed before the givenmodelis attached to the givenModelContextCreates a new empty model instance.booleanReturnstrueif for the given model a source Item exists and if this item Item#isAlive()getAttributeValue(Object model, String attributeQualifier) Generic attribute value getter to read attribute data from arbitrary model instances.getDirtyAttributes(Object model) Returns a map with all modified attribute qualifiers for the given model.getLocalizedAttributeValue(Object model, String attributeQualifier, Locale locale) Generic attribute value getter to read attribute data from arbitrary model instances.getPartOfAttributes(TypeService typeService) Returns a collection of all partof atrributesgetPersistenceSource(Object model) Deprecated, for removal: This API element is subject to removal in a future version.since 5.7.0Returns the exact type of the given model.getWritablePartOfAttributes(TypeService typeService) Returns a collection of writable partof atrributesvoidinit(ConverterRegistry registry) Called once before using the converter the first time.booleanisModified(Object model) Returnstrueif the given model is new or the ModelValueHistory of the model contains changed attributes.booleanisModified(Object model, String attribute) Returnstrueif the given model is new or the ModelValueHistory for the given attribute (qualifier) was changed.booleanisModified(Object model, String attribute, Locale loc) Returnstrueif the given model is new or the ModelValueHistory for the given attribute (qualifier) was changed.booleanReturnstrueif the given model was not persisted yet.booleanReturnstrueif for the given model no source Item exists or this item is not Item#isAlive()booleanisUpToDate(Object model) The given model is not up-to-date (returnsfalse) when: the model is new (seeisNew(Object)) or the model was removed (seeisRemoved(Object)) or the model was locally modified or the Item in the database is newer as the source item of the modelCreates a new model instance and fills its attributes with data from given source objectvoidFills the attributes of passed model new using mapped source object.voidTries to remove the source of the given model.voidsave(Object model, Collection<String> exclude) Saves all attribute values from the model to the wrapped source object or creates a new one if no source is mapped yet.voidsetAttributeValue(Object model, String attributeQualifier, Object value) Generic attribute value setter to modify attribute data on arbitrary model instances.
-
Method Details
-
init
Called once before using the converter the first time.- Parameters:
registry- the registry holding this converter.
-
create
Creates a new empty model instance.- Returns:
- new empty model
-
getType
Returns the exact type of the given model. -
load
Creates a new model instance and fills its attributes with data from given source object- Parameters:
source- object which will be used for filling new model- Returns:
- new model instance with data of given source
-
reload
Fills the attributes of passed model new using mapped source object.- Parameters:
model- model which will be filled from scratch using mapped source
-
remove
Tries to remove the source of the given model.- Parameters:
model- the model for which to remove the source
-
save
Saves all attribute values from the model to the wrapped source object or creates a new one if no source is mapped yet.- Parameters:
model- the model to save
-
getSource
Deprecated, for removal: This API element is subject to removal in a future version.since 5.7.0Returns underlying source for given model.- 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
-
isModified
Returnstrueif the given model is new or the ModelValueHistory of the model contains changed attributes.- Parameters:
model- the model- Returns:
falseotherwise
-
isModified
Returnstrueif 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.- Parameters:
model- the modelattribute- the attribute qualifier- Returns:
falseif the attribute was not modified.
-
isModified
Returnstrueif the given model is new or the ModelValueHistory for the given attribute (qualifier) was changed. For localized attributes the givenLocaleis used to check for modifications. If the Locale isnullthen all Locales will be checked for modifications. For non-localized attributes the given Locale will be ignored.- Parameters:
model- the modelattribute- the attribute qualifierloc- the Locale. Can benull.- Returns:
falseotherwise.
-
exists
Returnstrueif for the given model a source Item exists and if this item Item#isAlive()- Parameters:
model- the model- Returns:
falseif the model was not persisted yet (no underlying item) or the item was removed.
-
isRemoved
Returnstrueif for the given model no source Item exists or this item is not Item#isAlive()- Parameters:
model- the model- Returns:
falseif the modelisNew(Object)or the item is alive.
-
isNew
Returnstrueif the given model was not persisted yet.- Parameters:
model- the model- Returns:
falseif an AttributeProvider for the given model exists.
-
isUpToDate
The given model is not up-to-date (returnsfalse) when:- the model is new (see
isNew(Object)) or - the model was removed (see
isRemoved(Object)) or - the model was locally modified or
- the Item in the database is newer as the source item of the model
- Parameters:
model- the model- Returns:
trueif the model is up-to-date
- the model is new (see
-
getDirtyAttributes
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 isnullthe key is a non-localized attribute qualifier else the map value contains the locale in which language the localized attribute was modified.- Parameters:
model- the new (not saved) model- Returns:
- a map with all modified attribute qualifier.
-
getAttributeValue
Generic attribute value getter to read attribute data from arbitrary model instances.- Parameters:
model- the model instanceattributeQualifier- the attribute qualifier- Returns:
- the attribute value
-
getLocalizedAttributeValue
Generic attribute value getter to read attribute data from arbitrary model instances.- Parameters:
model- the model instanceattributeQualifier- the attribute qualifierlocale- Locale for which value will be returned- Returns:
- the attribute value
-
setAttributeValue
Generic attribute value setter to modify attribute data on arbitrary model instances.- Parameters:
model- the modelattributeQualifier- the attribute qualifiervalue- the attribute value
-
beforeAttach
This method is executed before the givenmodelis attached to the givenModelContext -
afterDetach
This method is executed after the givenmodelis attached from the givenModelContext -
getWritablePartOfAttributes
Returns a collection of writable partof atrributes -
getPartOfAttributes
Returns a collection of all partof atrributes -
getPersistenceSource
-