I am writing here to get some clue regarding the problem I'm facing.
I am actually writing a service that will send text messages using some third party API. I've lots of message templates (static text and placeholders for dynamic content) that needs to be sent out and this service will be called from multiple modules with-in my application.
What I've planned is to store message templates in database and once any module require to send text message it will call my messaging service and pass data require to fill up the placeholders for a particular template.
I am saving my templates in database as follows:
{
"data": {
"message": "[GREETING], this is the test message sent on [DATE].",
"constant1": "",
"constant2": ""
},
"metadata": {
"data": {
"message": {
"[GREETING]": "required",
"[DATE]": "required"
},
"constant1": "required",
"constant2": "required",
"constant3": "optional"
}
}
}
data is the actual object I want eventually to pass messaging api and metadata is basically the constants and variables that are required/optional to complete data object.
and the data I'm receiving from other modules that are calling my service is:
{
"[GREETING]": "Dear John Doe",
"[DATE]": "28 February",
"data": {
"constant1": 982042,
"constant2": [64238, 64239]
}
}
So the issue is, I've to verify that all the required constant that are set required in templates metadata should be present the the json I'm receiving while my service is being called. I'm bit confused here of how I can compare the keys of data with template to make sure all the required data of template is sent by the module that has just called my service.
Can someone give me a clue if it's even possible in java ?
p.s: I just want some guidance or clue.
Thanks
Update: if someone have better and neat suggestion in achieving what I want to achieve in above mentioned scenario, please share I would really appreciate that.
Update2: Clarification of what I actually want to achieve: I've a JSON template in which I have a metadata field that tells me which parameters are required to fill up this specific template. So upon receiving call to my service, I've to first check that required parameters (set in metadata of templates) should be there in API request body. Hope that clears my requirements now.