DVM – Domain Value Mapping
DVM – Domain value mapping as the name suggest is the approach of selecting values used in one domain for specific fields to the value used in other domain for same fields.
Longname | Shortname | Language | Capital |
Karnataka | KA | Kannada | Bangalore |
Tamilnadu | TN | Tamil | Chennai |
Andhrapradesh | AP | Telugu | Hyderbad |
Kerala | KL | Malayalam | Trivandram |
Here the column names are the different fields like Longname, Shortname, Language and Capital and these values are getting changed e.g. for each state like Karnataka or Tamilnadu
So we can think that in one domain Shortname can be used to capture State and whereas in another doimain Longname can be used to capture State but their other details will still hold true e.g. Capital or Language or any other fact
To implement such scenario in MuleSoft we have to use YAML as properties file
To Start with – we will create a mule API which will accept Longname or Shortname as input and return different information from the above table
Create a project which will accept state as query parameter
Let’s create YAML to reflect above table structure – CountryDVM.yaml
State: Karnataka: Longname: "Karnataka" Shortname: "KA" Language: "Kannada" Capital: "Bangalore" KA: Longname: "Karnataka" Shortname: "KA" Language: "Kannada" Capital: "Bangalore" Tamilnadu: Longname: "Tamilnadu" Shortname: "TN" Language: "Tamil" Capital: "Chennai" TN: Longname: "Tamilnadu" Shortname: "TN" Language: "Tamil" Capital: "Chennai" Andhrapradesh: Longname: "Andhrapradesh" Shortname: "AP" Language: "Telugu" Capital: "Hyderbad" AP: Longname: "Andhrapradesh" Shortname: "AP" Language: "Telugu" Capital: "Hyderbad" Kerala: Longname: "Kerala" Shortname: "KL" Language: "Malayalam" Capital: "Trivandram" KL: Longname: "Kerala" Shortname: "KL" Language: "Malayalam" Capital: "Trivandram"
Create a configuration properties entry to read YAML as properties file
Now we will add a transformation to create response from the YAML properties file
Dataweave:
%dw 2.0 output application/json var inputState = attributes.queryParams.state --- { (if (sizeOf(p('State.' ++ inputState ++ '.Longname') default "") > 0) ( { Longname: p('State.' ++ inputState ++ '.Longname'), Shortname: p('State.' ++ inputState ++ '.Shortname'), Language: p('State.' ++ inputState ++ '.Language'), Capital: p('State.' ++ inputState ++ '.Capital') } ) else ( { "message": "info not available" } )) }
Advantages of having DVM approach
- If new information comes then it will be added into YAML file e.g. add states
- YAML provide a better readable structure which is more hierarchical
- If one domain retrieve the values on the basis of Longname and other on Shortname then both can use the same DVM
- If new domain comes e.g. Initials then we can extend the DVM to accommodate new domain
Now if we test this API in SOAP UI
Will get valid response for available states – Tamilnadu
states – TN
For unavailable states
Sample mule application – dvm-sample-service
Sample SOAP UI project – dvm-sample-service-soapui-project