public class ItemModelConverter extends Object implements Cloneable, UpdateableModelConverter, TypeSystemAwareModelConverter
ModelConverter implementation which should be working for almost every
AbstractItemModel. Using the
ItemModelConverter(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 in load(Object)) and which ItemModel class will be created if you load such an item using
load(Object) . If you need functionality which is beyond this simple implementation, you will have to
provide your own ItemModel implementation.| Modifier and Type | Class and 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 |
| Constructor and Description |
|---|
ItemModelConverter(ModelService modelService,
I18NService i18nService,
CommonI18NService commonI18NService,
String type,
Class<? extends AbstractItemModel> modelClass,
SerializationStrategy serializationStrategy)
For backward compatibility
|
ItemModelConverter(ModelService modelService,
I18NService i18nService,
CommonI18NService commonI18NService,
String type,
Class<? extends AbstractItemModel> modelClass,
SerializationStrategy serializationStrategy,
SourceTransformer sourceTransformer,
SelfHealingService selfHealingService)
Constructs a new
ItemModelConverter instance which handles beans of given class type related to given
composed type. |
| Modifier and Type | Method and Description |
|---|---|
void |
addModelModificationListener(Object model,
ModelModificationListener listener)
Adds the given
ModelModificationListener to the given model. |
void |
afterDetach(Object model,
ModelContext ctx)
This method is executed after the given
model is attached from the given
ModelContext |
void |
afterModification(AbstractItemModel model,
PK pk,
long persistenceVersion) |
protected de.hybris.platform.servicelayer.internal.converter.impl.ItemModelConverter.TypeMetaInfo |
assembleMetaInfo(ComposedType ct,
Collection<ItemModelConverter.TypeAttributeInfo> attributes)
Initializes
ItemModelConverter.TypeMetaInfo._modelAttributesAll
and
ItemModelConverter.TypeMetaInfo._modelAttributesInitial
using attribute meta infos. |
void |
beforeAttach(Object model,
ModelContext ctx)
This method is executed before the given
model is attached to the given
ModelContext |
protected Collection<ItemModelConverter.TypeAttributeInfo> |
calculateTypeAttributeInfos(ComposedType ct)
Calculates attribute meta info objects for a given composed type.
|
protected void |
clearAttribute(AbstractItemModel model,
String qualifier) |
protected void |
clearLocAttribute(AbstractItemModel model,
String qualifier,
Locale loc) |
protected Object |
convertModelsToObjects(AbstractItemModel model,
String qualifier,
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 Object |
convertObjectsToModels(PersistenceObject item,
String qualifier,
Object value)
Tries to convert given object, collection of objects or map of objects to related model instances.
|
AbstractItemModel |
create(String type)
Instantiates a new instance of configured model class.
|
protected ItemModelInternalContext |
createContextForExistingModel(String type,
PK pk,
long persistenceVersion,
AttributeProvider attributeProvider) |
protected ItemModelInternalContext |
createContextForNewModel(String type) |
protected AbstractItemModel |
createModelInstance(ItemModelInternalContext ctx) |
protected PersistenceObject |
createNewItem(AbstractItemModel model,
ItemModelConverter.ModifiedAttributeValues values)
Performs item creation.
|
boolean |
exists(Object model)
Returns
true 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.
|
List<ItemModelConverter.ModelAttributeInfo> |
getAllModelAttributes() |
protected ItemModelConverter.AttributesToLoad |
getAttributesToReload(AbstractItemModel model,
ItemModelConverter.ModifiedAttributeValues savedValues,
boolean forCreation) |
Object |
getAttributeValue(Object model,
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 of
ConfigIntf. |
String |
getDefaultType() |
Map<String,Set<Locale>> |
getDirtyAttributes(Object model)
Returns a map with all modified attribute qualifiers for the given model.
|
Object |
getDirtyAttributeValue(Object model,
String attributeQualifier)
Internal method for
DefaultModelService when inspecting dirty attributes during save! |
protected Set<String> |
getDirtyLocalizedAttributesWithNonDataLocales(Map<Locale,Set<String>> dirtyLocalizedAttributes,
Map<Locale,Set<Locale>> dataLocale2NonDataLocales) |
Object |
getDirtyLocalizedAttributeValue(Object model,
String attributeQualifier,
Locale locale)
Internal method for
DefaultModelService when inspecting dirty attributes during save! |
protected Set<ItemModelConverter.ModelAttributeInfo> |
getExcluded(Collection<String> excluded) |
protected Object |
getFieldValue(Object model,
ItemModelConverter.ModelAttributeInfo info) |
protected Method |
getGetter(Object model,
ItemModelConverter.ModelAttributeInfo info) |
protected I18NService |
getI18nService() |
ItemModelConverter.ModelAttributeInfo |
getInfo(String qualfier) |
List<ItemModelConverter.ModelAttributeInfo> |
getInitialModelAttributes() |
protected LocaleProvider |
getLocaleProvider() |
Object |
getLocalizedAttributeValue(Object model,
String attributeQualifier,
Locale locale)
Generic attribute value getter to read attribute data from arbitrary model instances.
|
protected Method |
getLocalizedGetter(Object model,
ItemModelConverter.ModelAttributeInfo info) |
protected Method |
getLocalizedSetter(Object model,
ItemModelConverter.ModelAttributeInfo info,
Object value) |
Set<String> |
getMandatoryAttributes() |
Set<String> |
getMandatoryAttributesForCreation() |
Class<? extends AbstractItemModel> |
getModelClass()
Gets the class used for instantiation of related models.
|
protected ModelService |
getModelService() |
PersistenceObject |
getPersistenceSource(Object model) |
SerializationStrategy |
getSerializationStrategy() |
protected Method |
getSetter(Object model,
ItemModelConverter.ModelAttributeInfo info,
Object value) |
Object |
getSource(Object model)
Deprecated.
Please use
getPersistenceSource(Object) |
protected Locale |
getStdLocale() |
String |
getType(Object model)
Returns the exact type of the given model.
|
protected String |
getTypeFromModelContext(Object model) |
Set<String> |
getUniqueAttributes() |
Set<String> |
getWritablePartOfAttributes(TypeService typeService)
Returns a collection of writable partof atrributes
|
protected boolean |
hasNonDataLocales(Map<Locale,Set<Locale>> dataLocale2LocaleMappings) |
void |
init(ConverterRegistry registry)
Called once before using the converter the first time.
|
boolean |
isConfiguredForLegacyPersistence() |
boolean |
isModified(Object model)
Returns
true if the given model is new or the ModelValueHistory of the model contains changed
attributes. |
boolean |
isModified(Object model,
String attribute)
Returns
true if the given model is new or the ModelValueHistory for the given attribute
(qualifier) was changed. |
boolean |
isModified(Object model,
String attribute,
Locale loc)
Returns
true if the given model is new or the ModelValueHistory for the given attribute
(qualifier) was changed. |
boolean |
isNew(Object model)
Returns
true 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(Object model)
Returns
true if for the given model no source Item exists or this item is not Item#isAlive() |
boolean |
isUpToDate(Object model)
The given model is not up-to-date (returns
false) 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
|
boolean |
jaloOnlyAttribute(String qualifier) |
AbstractItemModel |
load(Object source)
Instantiates a new instance of configured model class for the given source
Item and loads all of its
attributes. |
protected void |
mergeNonDataLocales(AbstractItemModel model) |
LocMap<Locale,Object> |
mergeOldValuesIntoDataLocales(Map<Locale,Set<Locale>> dataLocale2LocaleMappings,
String qualifier,
LocMap<Locale,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,
String qualifier,
Object value) |
protected void |
preLoadLocAttribute(Map<String,LocMap<Locale,Object>> localizedAttributtesFieldValue,
AbstractItemModel model,
String qualifier,
Locale loc,
Object value) |
protected ItemModelConverter.LoadedAttributeValues |
readAttributes(Locale dataLoc,
PersistenceObject item,
Set<String> qualifiers)
Performs bulk-reading of item attribute values,
|
protected AttributePrefetchMode |
readPrefetchSettings()
Reads configuration setting
ServicelayerConstants.PARAM_PREFETCH and determines preFetch mode. |
protected Object |
readSingleAttribute(Locale dataLoc,
PersistenceObject item,
String qualifier)
Performs reading for a single item attribute.
|
void |
reload(Object modelOriginal)
Clears all attributes of given bean so that they will be reloaded on next request.
|
void |
remove(Object model)
Tries to remove the source
Item of the given AbstractItemModel. |
void |
removeModelModificationListener(Object model,
ModelModificationListener listener)
Removes the ModelModificationListener from the given model.
|
void |
save(Object model,
Collection<String> excludedAttributes)
Takes all modified values from the given
AbstractItemModel and writes them down to the source Item (if it
exists). |
protected void |
setAttributeLoadError(AbstractItemModel model,
String qualifier,
ModelLoadingException error) |
void |
setAttributeValue(Object model,
String attributeQualifier,
Object value)
Generic attribute value setter to modify attribute data on arbitrary model instances.
|
protected void |
setLocAttributeLoadError(AbstractItemModel model,
String qualifier,
Locale loc,
ModelLoadingException error) |
protected void |
storeAttributes(Item item,
ItemModelConverter.ModifiedAttributeValues values)
Performs storing of item attribute values.
|
String |
toString() |
void |
typeSystemChanged()
Type system was changed and converter will respect this changes.
|
void |
unloadAttributes(AbstractItemModel model) |
public ItemModelConverter(ModelService modelService, I18NService i18nService, CommonI18NService commonI18NService, String type, Class<? extends AbstractItemModel> modelClass, SerializationStrategy serializationStrategy)
public ItemModelConverter(ModelService modelService, I18NService i18nService, CommonI18NService commonI18NService, String type, Class<? extends AbstractItemModel> modelClass, SerializationStrategy serializationStrategy, SourceTransformer sourceTransformer, SelfHealingService selfHealingService)
ItemModelConverter instance which handles beans of given class type related to given
composed type.type - specifies the type this handler can handle, is used in save(Object, Collection) if a new item
instance is createdmodelClass - specifies which AbstractItemModel class will be used to instantiate a new model via
load(Object)protected AttributePrefetchMode readPrefetchSettings()
ServicelayerConstants.PARAM_PREFETCH and determines preFetch mode. Method is
called once initially for each ItemModelConverter instance.
ServicelayerConstants.VALUE_PREFETCH_DEFAULT or no value means
protected ConfigIntf getConfig()
ConfigIntf. This allows overriding e.g. for test cases.public List<ItemModelConverter.ModelAttributeInfo> getInitialModelAttributes()
public List<ItemModelConverter.ModelAttributeInfo> getAllModelAttributes()
public ItemModelConverter.ModelAttributeInfo getInfo(String qualfier)
public AbstractItemModel create(String type)
create in interface ModelConverterpublic boolean isConfiguredForLegacyPersistence()
protected AbstractItemModel createModelInstance(ItemModelInternalContext ctx)
protected ItemModelInternalContext createContextForNewModel(String type)
protected ItemModelInternalContext createContextForExistingModel(String type, PK pk, long persistenceVersion, AttributeProvider attributeProvider)
public final AbstractItemModel load(Object source)
Item and loads all of its
attributes.load in interface ModelConvertersource - object which will be used for filling new modelIllegalArgumentException - if the given source object is not compatible with the item class provided in this classes constructor.public void addModelModificationListener(Object model, ModelModificationListener listener)
UpdateableModelConverterModelModificationListener to the given model.addModelModificationListener in interface UpdateableModelConverterpublic void removeModelModificationListener(Object model, ModelModificationListener listener)
UpdateableModelConverterremoveModelModificationListener in interface UpdateableModelConverterpublic void beforeAttach(Object model, ModelContext ctx)
ModelConvertermodel is attached to the given
ModelContextbeforeAttach in interface ModelConverterprotected void mergeNonDataLocales(AbstractItemModel model)
public LocMap<Locale,Object> mergeOldValuesIntoDataLocales(Map<Locale,Set<Locale>> dataLocale2LocaleMappings, String qualifier, LocMap<Locale,Object> oldLocValues)
protected Set<String> getDirtyLocalizedAttributesWithNonDataLocales(Map<Locale,Set<String>> dirtyLocalizedAttributes, Map<Locale,Set<Locale>> dataLocale2NonDataLocales)
protected boolean hasNonDataLocales(Map<Locale,Set<Locale>> dataLocale2LocaleMappings)
public void afterDetach(Object model, ModelContext ctx)
ModelConvertermodel is attached from the given
ModelContextafterDetach in interface ModelConverterpublic Set<String> getWritablePartOfAttributes(TypeService typeService)
ModelConvertergetWritablePartOfAttributes in interface ModelConverterpublic void reload(Object modelOriginal)
reload in interface ModelConvertermodelOriginal - model which will be filled from scratch using mapped sourcepublic void remove(Object model)
Item of the given AbstractItemModel.remove in interface ModelConvertermodel - the model for which to remove the sourceIllegalArgumentException - if the given model is not of type ItemModelpublic void save(Object model, Collection<String> excludedAttributes)
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.save in interface ModelConvertermodel - the model to saveIllegalArgumentException - if the given model is not an instance of ItemModelIllegalStateException - if the source item of the model doesn't exist any morepublic void afterModification(AbstractItemModel model, PK pk, long persistenceVersion)
public void unloadAttributes(AbstractItemModel model)
protected Set<ItemModelConverter.ModelAttributeInfo> getExcluded(Collection<String> excluded)
@Deprecated public Object getSource(Object model)
getPersistenceSource(Object)Item is returned.getSource in interface ModelConvertermodel - the model for which to return the sourceIllegalArgumentException - if the given bean is not of type AbstractItemModelIllegalStateException - is the model has never been persisted or the underlying item does not exist any morepublic PersistenceObject getPersistenceSource(Object model)
getPersistenceSource in interface ModelConverterpublic boolean isModified(Object model)
ModelConvertertrue if the given model is new or the ModelValueHistory of the model contains changed
attributes.isModified in interface ModelConvertermodel - the modelfalse otherwisepublic boolean isModified(Object model, String attribute)
ModelConvertertrue 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.isModified in interface ModelConvertermodel - the modelattribute - the attribute qualifierfalse if the attribute was not modified.public boolean isModified(Object model, String attribute, Locale loc)
ModelConvertertrue 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.isModified in interface ModelConvertermodel - the modelattribute - the attribute qualifierloc - the Locale. Can be null.false otherwise.public boolean exists(Object model)
ModelConvertertrue if for the given model a source Item exists and if this item Item#isAlive()exists in interface ModelConvertermodel - the modelfalse if the model was not persisted yet (no underlying item) or the item was removed.public boolean isRemoved(Object model)
ModelConvertertrue if for the given model no source Item exists or this item is not Item#isAlive()isRemoved in interface ModelConvertermodel - the modelfalse if the model ModelConverter.isNew(Object) or the item is alive.public boolean isNew(Object model)
ModelConvertertrue if the given model was not persisted yet.isNew in interface ModelConvertermodel - the modelfalse if an AttributeProvider for the given model exists.public boolean isUpToDate(Object model)
ModelConverterfalse) when:
ModelConverter.isNew(Object)) orModelConverter.isRemoved(Object)) orisUpToDate in interface ModelConvertermodel - the modeltrue if the model is up-to-datepublic Object getAttributeValue(Object model, String attributeQualifier)
ModelConvertergetAttributeValue in interface ModelConvertermodel - the model instanceattributeQualifier - the attribute qualifierpublic Object getDirtyAttributeValue(Object model, String attributeQualifier)
DefaultModelService when inspecting dirty attributes during save!public Object getLocalizedAttributeValue(Object model, String attributeQualifier, Locale locale)
ModelConvertergetLocalizedAttributeValue in interface ModelConvertermodel - the model instanceattributeQualifier - the attribute qualifierlocale - Locale for which value will be returnedpublic Object getDirtyLocalizedAttributeValue(Object model, String attributeQualifier, Locale locale)
DefaultModelService when inspecting dirty attributes during save!public void setAttributeValue(Object model, String attributeQualifier, Object value)
ModelConvertersetAttributeValue in interface ModelConvertermodel - the modelattributeQualifier - the attribute qualifiervalue - the attribute valuepublic Class<? extends AbstractItemModel> getModelClass()
public String getDefaultType()
public String getType(Object model)
ModelConvertergetType in interface ModelConverterprotected ComposedType getComposedType(AbstractItemModel model)
protected Object readSingleAttribute(Locale dataLoc, PersistenceObject item, String qualifier)
dataLoc - the locale to be useditem - the item to read fromqualifier - the attribute qualifierpublic boolean jaloOnlyAttribute(String qualifier)
protected Collection<ItemModelConverter.TypeAttributeInfo> calculateTypeAttributeInfos(ComposedType ct)
protected boolean isReferenceAttribute(AttributeDescriptor desc)
protected de.hybris.platform.servicelayer.internal.converter.impl.ItemModelConverter.TypeMetaInfo assembleMetaInfo(ComposedType ct, Collection<ItemModelConverter.TypeAttributeInfo> attributes)
ItemModelConverter.TypeMetaInfo._modelAttributesAll
and
ItemModelConverter.TypeMetaInfo._modelAttributesInitial
using attribute meta infos. Must be called with active write lock!!protected ItemModelConverter.LoadedAttributeValues readAttributes(Locale dataLoc, PersistenceObject item, Set<String> qualifiers)
item - the item to read fromqualifiers - the attributes to load values forprotected void storeAttributes(Item item, ItemModelConverter.ModifiedAttributeValues values)
item - the item to write intovalues - the (jalo compatible!) values to storeprotected boolean isNonLazyLoadedAttribute(AttributeDescriptor desc)
desc - the attribute descriptorprotected boolean mustConvert(Type type)
type - the type to checkisNonLazyLoadedAttribute(AttributeDescriptor)protected Locale getStdLocale()
protected PersistenceObject createNewItem(AbstractItemModel model, ItemModelConverter.ModifiedAttributeValues values)
ComposedType.newInstance(Map).values - the attributes for the new itemprotected void fillModel(AbstractItemModel model, ItemModelConverter.AttributesToLoad attributesToLoad, PersistenceObject item)
model - the model instance to fill values intoattributesToLoad - the attributes to be loadedprotected void setLocAttributeLoadError(AbstractItemModel model, String qualifier, Locale loc, ModelLoadingException error)
protected void setAttributeLoadError(AbstractItemModel model, String qualifier, ModelLoadingException error)
protected void preLoadLocAttribute(Map<String,LocMap<Locale,Object>> localizedAttributtesFieldValue, AbstractItemModel model, String qualifier, Locale loc, Object value)
protected void clearLocAttribute(AbstractItemModel model, String qualifier, Locale loc)
protected void preLoadAttribute(AbstractItemModel model, String qualifier, Object value)
protected void clearAttribute(AbstractItemModel model, String qualifier)
protected Object convertModelsToObjects(AbstractItemModel model, String qualifier, Object value)
value - model, collection of models or map of models to convertprotected Object convertObjectsToModels(PersistenceObject item, String qualifier, Object value)
value - object, collection of objects or map of objects to convert to model/sprotected ItemModelConverter.AttributesToLoad getAttributesToReload(AbstractItemModel model, ItemModelConverter.ModifiedAttributeValues savedValues, boolean forCreation)
public void init(ConverterRegistry registry)
ModelConverterinit in interface ModelConverterregistry - the registry holding this converter.protected ModelService getModelService()
protected I18NService getI18nService()
protected CommonI18NService getCommonI18NService()
protected LocaleProvider getLocaleProvider()
protected Method getGetter(Object model, ItemModelConverter.ModelAttributeInfo info)
protected Method getLocalizedGetter(Object model, ItemModelConverter.ModelAttributeInfo info)
protected Method getSetter(Object model, ItemModelConverter.ModelAttributeInfo info, Object value)
protected Method getLocalizedSetter(Object model, ItemModelConverter.ModelAttributeInfo info, Object value)
public SerializationStrategy getSerializationStrategy()
protected final Object getFieldValue(Object model, ItemModelConverter.ModelAttributeInfo info)
public Map<String,Set<Locale>> getDirtyAttributes(Object model)
ModelConverternull the key is a
non-localized attribute qualifier else the map value contains the locale in which language the localized attribute
was modified.getDirtyAttributes in interface ModelConvertermodel - the new (not saved) modelpublic void typeSystemChanged()
TypeSystemAwareModelConvertertypeSystemChanged in interface TypeSystemAwareModelConverterCopyright © 2017 SAP SE. All Rights Reserved.