Class ItemToMapConversionContext
- java.lang.Object
-
- de.hybris.platform.integrationservices.populator.ItemToMapConversionContext
-
public class ItemToMapConversionContext extends java.lang.ObjectThis class encapsulates the context of a conversion from anItemModelto aMap
-
-
Constructor Summary
Constructors Constructor Description ItemToMapConversionContext(ItemModel data, IntegrationObjectItemModel metadata)Instantiates a top level context.ItemToMapConversionContext(ItemModel data, TypeDescriptor metadata)Instantiates a top level context.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ItemToMapConversionContextcreateSubContext(ItemModel itemModel, IntegrationObjectItemModel objItemModel)Creates sub-context from this context.ItemToMapConversionContextcreateSubContext(ItemModel itemModel, TypeDescriptor descriptor)Creates sub-context from this context.java.util.Map<java.lang.String,java.lang.Object>getConversionResult()Retrieves a conversion result for the item in this context.ItemModelgetItemModel()Retrieves the item being converted.protected ItemToMapConversionContextgetParentContext()Retrieves parent context.TypeDescriptorgetTypeDescriptor()Retrieves the integration object item descriptor associated with the conversion.voidsetConversionResult(java.util.Map<java.lang.String,java.lang.Object> result)Sets conversion result for the item in this context.java.lang.StringtoString()
-
-
-
Constructor Detail
-
ItemToMapConversionContext
public ItemToMapConversionContext(ItemModel data, IntegrationObjectItemModel metadata)
Instantiates a top level context. The top level context does not have parent context associated with it.- Parameters:
data- item being converted.metadata- integration object item describing the structure of the conversion result, e.g. if thedatais being converted to aMap, then what attributes the map should have.- See Also:
getParentContext()
-
ItemToMapConversionContext
public ItemToMapConversionContext(ItemModel data, TypeDescriptor metadata)
Instantiates a top level context. The top level context does not have parent context associated with it.- Parameters:
data- item being converted.metadata- integration object item descriptor defining the structure of the conversion result, e.g. if thedatais being converted to aMap, then what attributes the map should have.- See Also:
getParentContext()
-
-
Method Detail
-
getItemModel
public ItemModel getItemModel()
Retrieves the item being converted.- Returns:
- item being converted.
-
getTypeDescriptor
public TypeDescriptor getTypeDescriptor()
Retrieves the integration object item descriptor associated with the conversion.- Returns:
- metadata describing the structure of the conversion result.
-
getParentContext
protected ItemToMapConversionContext getParentContext()
Retrieves parent context.- Returns:
- conversion context from which this context was created or
null, if the context was created independently by the constructor. - See Also:
createSubContext(ItemModel, IntegrationObjectItemModel)
-
createSubContext
public ItemToMapConversionContext createSubContext(ItemModel itemModel, IntegrationObjectItemModel objItemModel)
Creates sub-context from this context.- Parameters:
itemModel- data item to be used in the context to createobjItemModel- integration object item to be used in the context to create- Returns:
- a new conversion context with current context as its parent.
-
createSubContext
public ItemToMapConversionContext createSubContext(ItemModel itemModel, TypeDescriptor descriptor)
Creates sub-context from this context.- Parameters:
itemModel- data item to be used in the context to createdescriptor- integration object item descriptor to be used in the context to create- Returns:
- a new conversion context with current context as its parent.
-
setConversionResult
public void setConversionResult(java.util.Map<java.lang.String,java.lang.Object> result)
Sets conversion result for the item in this context.- Parameters:
result- map, to which thegetItemModel()was converted.
-
getConversionResult
public java.util.Map<java.lang.String,java.lang.Object> getConversionResult()
Retrieves a conversion result for the item in this context. Because this method is used to retrieve result of current item conversion in the parent contexts, so that it can be injected to a nested item, this method returns only a map containing only key attribute values of the previously converted item. Without limiting the conversion result to key attributes there is a risk of causing an infinite loop in the conversion result structure.Consider this. We need to convert an Order, which has code attribute (its key) and a collection of OrderEntry items. Each OrderEntry has a reference back to the Order it belongs to, some entryNumber attribute, which makes the entry unique when combined with the Order, and some other meaningful attributes, e.g. Product the line is associated with, quantity (how many products purchased), etc. During conversion when we will get to OrderEntry conversion and will attempt to convert its
orderattribute value we will detect that the Order has been converted already into a map. However, if we just take that map "as is" it will contain theorderEntries, each OrderEntry refers to the Order again and thus an infinite loop is formed. For that reason, for OrderEntries we include Order map with key attribute values only, i.e.codeattribute.- Returns:
- a map containing key attribute values for the previous conversion result that was added to this context or to the
parent(s) of this context. If the specified item was not converted yet, then
nullis returned.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-