Class ExpressionSupport

java.lang.Object
org.chenile.cconfig.util.ExpressionSupport

public class ExpressionSupport extends Object
Use this class if you have a list of Cconfigs which need to manipulate an existing set of keys.
  • Field Details

    • logger

      private static final org.slf4j.Logger logger
    • objectMapper

      private static final ObjectMapper objectMapper
    • parser

      private static final ExpressionParser parser
  • Constructor Details

    • ExpressionSupport

      public ExpressionSupport()
  • Method Details

    • augmentKeys

      public static void augmentKeys(Map<String,Object> keys, List<Cconfig> configList)
    • addMissingKeys

      private static void addMissingKeys(Map<String,Object> keys, List<Cconfig> cconfigList)
      Add all keys from cconfigList whose path is null to the key list. They might have been defined for the first time or perhaps they might have been redefined in the config retriever. Add only the keys that are missing in the key list.(i.e. keys defined for the first time in the cconfig and are not present in the key list)
      Parameters:
      keys - - the existing set of keys that will be augmented.
      cconfigList - - the list of all cconfigs. This will manipulate the keys
    • overrideKeys

      private static void overrideKeys(Map<String,Object> keys, List<Cconfig> configList)
      For every key from JSON make sure that you override it if there are records available in the cconfig
      Parameters:
      keys - - the existing keys
      configList - - the cconfig list that will override these key values.
    • override

      private static Object override(String key, Object value, List<Cconfig> configList)
      Parameters:
      key - the key
      value - the original value either from JSON or from the first record found with path null in DB
      configList - the list of all keys obtained for the module and the custom attribute.
      Returns:
      the modified value after all the operations in dblist are applied against the key
    • mapExpression

      private static String mapExpression(String p)
      Convert the path expression from form "a.b.c" to ['a']['b']['c'] as supported by SPEL for maps. Note that even if expression contains indexes this handles it. Example: a.0.xyz becomes ['a']['0']['xyz']
      Parameters:
      p - the path defined in the database
      Returns:
      the expression in a form that is amenable to be used as a SPEL expression for maps
    • evaluate

      private static Object evaluate(String key, String path, Object value, String dbValue)
      Parameters:
      key - the key
      path - the path in the value that has been modified to a new value
      value - the original value that will be modified
      dbValue - the db value that will be applied against the original record
      Returns:
      the modified value after SPEL constructs specified in the path are invoked on the original record
    • objectify

      private static Object objectify(String dbValue)
      Parses the string as JSON if applicable and returns the parsed string as map
      Parameters:
      dbValue - the value to objectify
      Returns:
      the string or map