Q:

Dataweave key value set from database to HashMap

My flow goes something like this:
I receive a payload with say the following:
['BobsFirstStatus', 'BobsSecondStatus', 'BobsEightStatus']
and I have a lookup table in my database like so:
ID_|_BobStatusName___|_InternalStatusName_____
1  | BobsFirstStatus | Internal_1stStatus
2  | BobsSecondStatus| Internal_2ndStatus
3  | BobsEighStatus  | Internal_3rdStatus

I want to read this data from the database, and load a HashMap to look like so:
{
  "BobsFirstStatus": "Internal_1stStatus",
  "BobsSecondStatus": "Internal_2ndStatus",
  "BobsEighStatus": "Internal_3rdStatus"
}

this way, I can in a data weave statement i can do a "flowVars.Lookup[payload.BobStatus]" to retrieve our internal mapping of the status.
anyone done this before? seems useful...

A:

Solid plan, although I don't like doing it in a flow variable. You can simply make a lookup flow, and call it from your DWL like so. You'll likely want to use Cache scope to avoid doing it every time.
I have done it in a spring bean before too, and I'm happy with the final result.  This is only for lookup tables that I expect to change only when the application is released, or less often.

Create a bean of type Map. You can use the native Spring <util:map> for this. Configure the lookup keys and values using spring <entry> elements
<util:map id="statusTable">
<entry key="BobsFirstStatus" value="Internal_1stStatus" />
<entry key="BobsSecondStatus" value="Internal_2ndStatus" />
<entry key="BobsEighStatus" value="Internal_3rdStatus" />
</util:map>
Refer to the bean using the MEL app context object
#[app.registry.statusTable[flowVars.status]]

