Class PropertyMapping
- java.lang.Object
-
- com.broadleafcommerce.metadata.dsl.core.Mapping<PropertyMapping>
-
- com.broadleafcommerce.metadata.dsl.core.extension.mappings.PropertyMapping
-
- All Implemented Interfaces:
Copyable<PropertyMapping>,Serializable
public class PropertyMapping extends Mapping<PropertyMapping> implements Serializable
An implementation ofMappingfor mapping a source value to its destination.- Author:
- Nick Crum (ncrum)
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPropertyMapping.DefaultOperations
-
Constructor Summary
Constructors Constructor Description PropertyMapping()PropertyMapping(PropertyMapping mapping)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleancanEqual(Object other)PropertyMappingcopy()PropertyMappingcopyFrom(boolean copyFrom)PropertyMappingcopyValue(String from, String to)Copies the source property and maps to the destination property.PropertyMappingcopyValue(String from, String to, Object defaultValue)Copies the source property and maps to the destination property.PropertyMappingdefaultValue(Object defaultValue)booleanequals(Object o)PropertyMappingfrom(String from)StringgetFrom()The name of the property to renameStringgetOperation()The type of operation applied when mapping the property.StringgetTo()The new name of the property.ObjectgetValue()inthashCode()booleanisCopy()Whether or not the property is copied.PropertyMappingmapValue(String from, String to)Maps the source's property to the destination's property.PropertyMappingmapValue(String from, String to, Object defaultValue)Maps the source's property to the destination's property with a default value.PropertyMappingmapValueFromRoot(String to)Maps theROOTto the destination.PropertyMappingmapValueToRoot(String from)Maps the source's property to theROOT.PropertyMappingmergeTo()PropertyMappingnullValue(String to)Sets the destination property to null.PropertyMappingoperation(String operation)PropertyMappingreplaceTo()PropertyMappingsetValue(String to, Object defaultValue)Sets the value on the destination.PropertyMappingto(String to)
-
-
-
Field Detail
-
ROOT
public static final String ROOT
Reference to the "root" object being mapped.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PropertyMapping
public PropertyMapping()
-
PropertyMapping
public PropertyMapping(PropertyMapping mapping)
-
-
Method Detail
-
copy
public PropertyMapping copy()
- Specified by:
copyin interfaceCopyable<PropertyMapping>- Returns:
- a deep copy of this instance
-
from
public PropertyMapping from(@Nullable String from)
-
to
public PropertyMapping to(@Nullable String to)
-
defaultValue
public PropertyMapping defaultValue(@Nullable Object defaultValue)
-
operation
public PropertyMapping operation(@Nullable String operation)
-
replaceTo
public PropertyMapping replaceTo()
-
mergeTo
public PropertyMapping mergeTo()
-
copyFrom
public PropertyMapping copyFrom(boolean copyFrom)
-
mapValue
public PropertyMapping mapValue(String from, String to)
Maps the source's property to the destination's property. Useful for mapping a property, for example:// mapValue("state", "region"); { state: "TX" } => { region: "TX" }- Parameters:
from- the source propertyto- the destination property- Returns:
- the mapping
-
mapValue
public PropertyMapping mapValue(String from, String to, @Nullable Object defaultValue)
Maps the source's property to the destination's property with a default value. Useful for when you need a useful default, for example:// mapValue("state", "region", "N/A"); { city: "Washington" } => { city: "Washington", region: "N/A" }- Parameters:
from- the source propertyto- the destination propertydefaultValue- the default value- Returns:
- the mapping
-
mapValueToRoot
public PropertyMapping mapValueToRoot(String from)
Maps the source's property to theROOT. Useful for reducing an object down to one of its properties, for example:// mapValueToRoot("label") { label: "RED" } => "RED"- Parameters:
from- the source property- Returns:
- the mapping
-
mapValueFromRoot
public PropertyMapping mapValueFromRoot(String to)
Maps theROOTto the destination. Useful for mapping an object to a property of a new object.// mapValueFromRoot("details") { label: "RED" } => { details: { label: "RED" } }- Parameters:
to- the destination property- Returns:
- the mapping
-
setValue
public PropertyMapping setValue(String to, @Nullable Object defaultValue)
Sets the value on the destination. Useful for defaulting the value of a property, for example:// setValue("state", "TX"); { city: "Austin" } => { city: "Austin", state: "TX" }- Parameters:
to- the destination propertydefaultValue- the default value of the property- Returns:
- the mapping
-
nullValue
public PropertyMapping nullValue(String to)
Sets the destination property to null. Useful for clearing out a value, for example:// nullValue("state"); { state: "TX" } => { state: null }- Parameters:
to- the destination property- Returns:
- the mapping
-
copyValue
public PropertyMapping copyValue(String from, String to)
Copies the source property and maps to the destination property. Useful for mapping a property while preserving the original value, for example:// copyValue("state", "region"); { state: "TX" } => { state: "TX", region: "TX" }- Parameters:
from- the source propertyto- the destination property- Returns:
- the mapping
-
copyValue
public PropertyMapping copyValue(String from, String to, @Nullable Object defaultValue)
Copies the source property and maps to the destination property. Useful for when you need a useful default, for example:// copyValue("state", "region", "TX"); { } => { region: "TX" }- Parameters:
from- the source propertyto- the destination propertydefaultValue- the default value- Returns:
- the mapping
-
getFrom
public String getFrom()
The name of the property to rename
-
getTo
public String getTo()
-
getOperation
public String getOperation()
The type of operation applied when mapping the property.
-
getValue
public Object getValue()
-
isCopy
public boolean isCopy()
Whether or not the property is copied. If false, the original property will be omitted.
-
equals
public boolean equals(Object o)
- Overrides:
equalsin classMapping<PropertyMapping>
-
canEqual
protected boolean canEqual(Object other)
- Overrides:
canEqualin classMapping<PropertyMapping>
-
hashCode
public int hashCode()
- Overrides:
hashCodein classMapping<PropertyMapping>
-
-