I’m relatively new to Apama. I’m using v10.3.1. I’m following the following snippet to do a REST request within a monitor:
The action to handle the response currently looks as follows:
action handleResponse(Response response){
if response.isSuccess(){
print "###The response payload is :" + response.payload.toString();
}
else {
print "###Request failed. Response status is: " + response.statusCode.toString() + " | " + response.statusMessage;
}
}
I’m looking for the best way to extract the value of the following property within the JSON response payload:
assetparents.references[0].managedObject.name (here “SOME”).
I tried different ways but always ran into an error.
The print statement provides the following output for the response payload:
###The response payload is :com.apama.util.AnyExtractor(any(string,"
{"owner":"[email protected]","additionParents":{
"self":"https://somebaseurl/inventory/managedObjects/5706999/additionParents","references":[]
},
"childDevices":{
"self":"https://somebaseurl/inventory/managedObjects/5706999/childDevices","references":[]
},
"childAssets":{
"self":"https://somebaseurl/inventory/managedObjects/5706999/childAssets","references":[]
},
"creationTime":"2019-05-09T11:36:10.197Z",
"lastUpdated":"2019-05-10T05:28:07.893Z",
"childAdditions":{
"self":"https://somebaseurl/inventory/managedObjects/5706999/childAdditions",
"references":[{
"managedObject":{"name":"Escalate alarmtest",
"self":"https://somebaseurl/inventory/managedObjects/5706698",
"id":"5706698"},
"self":"https://somebaseurl/inventory/managedObjects/5706999/childAdditions/5706698"
}
]},
"name":"SOME Test Device",
"deviceParents":{
"self":"https://somebaseurl/inventory/managedObjects/5706999/deviceParents",
"references":[]
},
"assetParents":{
"self":"https://somebaseurl/inventory/managedObjects/5706999/assetParents",
"references":[{
"managedObject":{
"additionParents":{
"self":"https://somebaseurl/inventory/managedObjects/5706682/additionParents",
"references":[]
},
"childDevices":{
"self":"https://somebaseurl/inventory/managedObjects/5706682/childDevices",
"references":[]
},
"childAssets":{
"self":"https://somebaseurl/inventory/managedObjects/5706682/childAssets",
"references":[]
},
"childAdditions":{
"self":"https://somebaseurl/inventory/managedObjects/5706682/childAdditions",
"references":[]
},
"name":"SOME",
"deviceParents":{
"self":"https://somebaseurl/inventory/managedObjects/5706682/deviceParents",
"references":[]
},
"assetParents":{
"self":"https://somebaseurl/inventory/managedObjects/5706682/assetParents",
"references":[]
},
"self":"https://somebaseurl/inventory/managedObjects/5706682",
"id":"5706682"
},
"self":"https://somebaseurl/inventory/managedObjects/5706999/assetParents/5706682"
}]
},
"self":"https://somebaseurl/inventory/managedObjects/5706999",
"id":"5706999",
"c8y_ActiveAlarmsStatus":{
"minor":0,
"critical":1
},
"c8y_IsDevice":{},
"ax_Customer":"SOME CUSTOMER",
"c8y_SupportedMeasurements":["c8y_Temperature"]}"))
Besides parsing the individual property, what is the recommended way to map the entire object to an Apama event?
If you could provide a code snippet it would be greatly appreciated.
Many thanks Mathias
To address your second question, namely "what is the recommended way to map the entire object to an Apama event?":
I've defined several events which will map to the JSON you provided:
Because a ManagedObject contains an Object, which contains a Reference which itself contains a ManagedObject, the EPL wouldn't compile due to the recursive types. Therefore, in Reference we use an any type to mask the ManagedObject. this allows the EPL to compile.
However, because an any hides the type, we don't know what type to convert it to, and so instead we have an any containing a dictionary. This is fine though, because we can use some helper functions to extract the information we want:
Using these helper functions, we can extract the information from our original event:
And there you have it! A fully mapped event.