CCCTC Docs

CCCTC Docs

  • Help

Value Mapper System Task

VALUE_MAPPER is a custom System Task for transforming values by running switch/case operations and/or java functions.

If switches and functions are both present, switches are run first, then functions are run on the result.

Functions are run iteratively, in order, so functions can be chained together, each operating off the result of the previous value. Functions may also utilize the values from other source values in their operations.

Sample as a task in a workflow

This sample shows what this would look as a task inside a workflow:

{
    "name": "value-mapper",
    "taskReferenceName": "hello-world-mapper",
    "type": "VALUE_MAPPER",
    "inputParameters": {
        "sources": {
            "switch-test": "hi",
            "function-test": "hello"
        },
        "switches": [
            {
                "source": "switch-test",
                "cases": {
                    "hi": "hello world",
                    "other case": "not hello world"
                },
                "nullCase": "null encountered!",
                "defaultValue": "no cases matched!"
            }
        ],
        "functions": [
            {
                "source": "function-test",
                "funcName": "concat",
                "funcArgs": [" world"]
            }
        ]
    }
}

task output:
{
    "switch-test": "hello world",
    "function-test": "hello world"
}

Switch Operations (switches):

This is a basic switch/case operation to translate a value. It has three commands (parameters) which are all optional and executed in order. If a command is not present in the JSON spec, it will not be evaluated.

  1. cases

    This is your basic switch/case for translating values. They are formatted as key/value pairs in the JSON spec. NOTE: Since the key in JSON must be a string, the comparison is type insensitive. However, the value does retain its type.

    This command is optional.

  2. nullCase

    This is the special switch/case where the source value is null.

    This command is optional.

  3. defaultCase

    If specified and none of the listed cases matches the source value (including the null case), then this value is returned.

    This command is optional. If not included in the spec and no cases match the source value, then the source value will be returned unchanged. This is different than specifying "null" as the defaultCase, which would return null if no case statements match.

Example #1 - convert HELLO to WORLD and vice-versa:
Input = {
     "sources": {
         "value1": "HELLO",
         "value2": "WORLD"
     },
     "switches": [
         {
             "source": "value1",
             "cases": {
                 "HELLO": "WORLD",
                 "WORLD": "HELLO"
             },
             "nullCase": "NULL",
             "defaultValue": "ERROR"
         },
         {
             "source": "value2",
             "cases": {
                 "HELLO": "WORLD",
                 "WORLD": "HELLO"
             },
             "nullCase": "NULL",
             "defaultValue": "ERROR"
         }
     ]
 }

 Output = {
     "value1": "WORLD",
     "value2": "HELLO"
}
Example #2 - pass through values
Input = {
     "sources": {
         "value1": "CHANGE-ME",
         "value2": "PASS-THRU"
     },
     "switches": [
         {
             "source": "value1",
             "cases": {
                 "CHANGE-ME": "NEW-VALUE"
             }
         },
         {
             "source": "value2",
             "cases": {
                 "CHANGE-ME": "NEW-VALUE"
             }
         }
     ]
 }

 Output = {
     "value1": "NEW-VALUE",
     "value2": "PASS-THRU"
 }

Function Operations (functions):

Each function spec allows us to call a single, public java method.

Function arguments may contain references to the source value via "@" or other source values by name "@value1".

Methods of the class of the object may be called by name (see example 1). Static methods of any class may be called by full package, class and method name (see example 2). In addition, as a short-cut, static methods defined in the org.ccctech.apigateway.conductor.util package may be called without specifying the package name (see example 6).

Example #3 - concatenate a string:
Input = {
     "sources": {
         "value": "hello"
     },
     "functions": [
         {
             "source": "value",
             "funcName": "concat",
             "funcArgs": [" world"]
         }
     ]
 }

 Output = {
     "value": "hello world"
 }
Example #4 - call a static method to convert string to integer:
Input = {
     "sources": {
         "number": "1"
     },
     "functions": [
         {
             "source": "number",
             "funcName": "java.lang.Integer.parseInt",
             "funcArgs": ["@"]
         }
     ]
 }

 Output = {
     "value": 1
 }
Example #5 - compute a pow() from two strings. first we need to convert the values to doubles then call pow.
Input = {
     "sources": {
         "pow-base": "10",
         "pow-exp": "3",
         "pow-result": null
     },
     "functions": [
         {
             "source": "pow-base",
             "funcName": "java.lang.Double.parseDouble",
             "funcArgs": ["@"]
         },
         {
             "source": "pow-exp",
             "funcName": "java.lang.Double.parseDouble",
             "funcArgs": ["@"]
         },
         {
             "source": "pow-result",
             "funcName": "java.lang.Math.pow",
             "funcArgs": ["@pow-base", "@pow-exp"]
         }
     ]
 }

 Output = {
     "pow-base": 10,
     "pow-exp": 3,
     "pow-result": 1000
 }
Example #6 - use a custom static method from this project (in org.ccctech.apigateway.conductor.util):
Input = {
    "sources": {
        "string-to-encode": "user:password"
    },
    "functions": [
        {
            "source": "string-to-encode",
            "funcName": "StringUtils.base64Encode",
            "funcArgs": ["@"]
        }
    ]
}


Output = {
    "string-to-encode": "(base 64 encoded string)"
}
  • Sample as a task in a workflow
  • Switch Operations (switches):
  • Function Operations (functions):