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 of Mapping for mapping a source value to its destination.
Author:
Nick Crum (ncrum)
See Also:
  • Field Details

  • Constructor Details

    • PropertyMapping

      public PropertyMapping()
    • PropertyMapping

      public PropertyMapping(PropertyMapping mapping)
  • Method Details

    • copy

      public PropertyMapping copy()
      Specified by:
      copy in interface Copyable<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 property
      to - 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 property
      to - the destination property
      defaultValue - the default value
      Returns:
      the mapping
    • mapValueToRoot

      public PropertyMapping mapValueToRoot(String from)
      Maps the source's property to the ROOT. 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 the ROOT to 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 property
      defaultValue - 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 property
      to - 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 property
      to - the destination property
      defaultValue - the default value
      Returns:
      the mapping
    • getFrom

      public String getFrom()
      The name of the property to rename
    • getTo

      public String getTo()
      The new name of the property. This can not be null or empty If this is equals to ROOT then all properties from from will be mapped to the root object.
    • getOperation

      public String getOperation()
      The type of operation applied when mapping the property.
    • getValue

      public Object getValue()
      The new value of the property with name to This is ignored if from is defined
    • 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:
      equals in class Mapping<PropertyMapping>
    • canEqual

      protected boolean canEqual(Object other)
      Overrides:
      canEqual in class Mapping<PropertyMapping>
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Mapping<PropertyMapping>