I am trying to learn Talend.
Scenario:
I have to create a REST endpoint (i am using tRESTRequest) which takes a POST request at http://localhost:8086/emp/create and accepts below json and prints each json field and sends a sample json response containing only name field.
How can I do so ?
How to read the json data into a java component like tJava?
Structure:
{
"emp" :
[
{
"id":"123",
"name": "testemp1"
},
{
"id":"456",
"name": "testemp2"
}
]
}
Expected Response:
{
"emp" :
[
{
"name": "testemp1"
},
{
"name": "testemp2"
}
]
}
I am using tRESTRequest -> tExtractJSONFields -> tRESTResponse.
For looping on the right elements and parsing the contents, please see my answer JSON Deserialization on Talend
I did not understand the second question. When deserializing JSON, the data will already be available in the usual row format for processing further. Beginner tutorials will show you the standard structure. The component tJava is - of course - an exception to that rule. Handling data is different in this component and not neccessarily row based.
Talend has an excellent knowledge base for components and examples, see https://help.talend.com/
Related
Good day! I'm trying to start the next Drools Business Process via REST
This process has the following process variable (named contractObject), which is populated at the beginning of the flow and used to validate with the decision table
I'm sending the next body in the Drools Request
{
"lookup": "ksession1",
"commands": [
{ "start-process": {
"processId":"decision-tree-test.businessProcessTest",
"out-identifier": "firedProcesses",
"data": [
{
"contractObject": {
"com.myspace.decision_tree_test.Contract":{
"contractType": "P",
"service": 2000,
"serviceType": 3000,
"promotion": 3470
}
}
}
]
}
}]
}
But i keep getting the next error
{
"type" : "FAILURE",
"msg" : "Error calling container decision-tree-test: [decision-tree-test.businessProcessTest:11 - Decision Table:5] -- [decision-tree-test.businessProcessTest:11 - ?:4] -- Exception when trying to evaluate constraint in split null",
"result" : null
}
So I guess I'm not sending the data well as it doesn't seem to be taking it. In the documentation they do not specify a specific format to send data for process variables, this is what I have found for the start-process command:
What could I be doing wrong?
Links to the documentation i've consulted:
https://access.redhat.com/documentation/en-us/red_hat_process_automation_manager/7.1/html-single/interacting_with_red_hat_process_automation_manager_using_kie_apis/index#runtime-commands-con_kie-apis
https://docs.jboss.org/drools/release/5.3.0.Final/droolsjbpm-integration-docs/html/ch04.html#d0e1028
Picture of the Decision Table Data I / O
sample json payload:
'{
"Stub1": "XXXXX",
"Stub2": "XXXXX-3047-4ed3-b73b-83fbcc0c2aa9",
"Code": "CodeX",
"people": [
{
"ID": "XXXXX-6425-EA11-A94A-A08CFDCA6C02"
"customer": {
"Id": 173,
"Account": 275,
"AFile": "tel"
},
"products": [
{
"product": 1,
"type": "A",
"stub1": "XXXXX-42E1-4A13-8190-20C2DE39C0A5",
"Stub2": "XXXXX-FC4F-41AB-92E7-A408E7F4C632",
"stub3": "XXXXX-A2B4-4ADF-96C5-8F3CDCF5821D",
"Stub4": "XXXXX-1948-4B3C-987F-B5EC4D6C2824"
},
{
"product": 2,
"type": "B",
"stub1": "XXXXX-42E1-4A13-8190-20C2DE39C0A5",
"Stub2": "XXXXX-FC4F-41AB-92E7-A408E7F4C632",
"stub3": "XXXXX-A2B4-4ADF-96C5-8F3CDCF5821D",
"Stub4": "XXXXX-1948-4B3C-987F-B5EC4D6C2824"
}
]
}
]
}'
I am working on a POST call. Is there any way to feed multiple json files as a payload in Gatling. I am using body(RawFileBody("file.json")) as json here.
This works fine for a single json file. I want to check response for multiple json files. Is there any way we can parametrize this and get response against multiple json files.
As far as I can see, there's a couple of ways you could do this.
Use a JSON feeder (https://gatling.io/docs/current/session/feeder#json-feeders). This would need your multiple JSON files to be in a single file, with the root element being a JSON array. Essentially you'd put the JSON objects you have inside an array inside a single JSON file
Create a Scala Iterator and have the names of the JSON files you're going to use in it. e.g:
val fileNames = Iterator("file1.json", "file2.json)
// and later, in your scenario
body(RawFileBody(fileNames.next())
Note that this method cannot be used across users, as the iterator will initialize separately for each user. You'd have to use repeat or something similar to send multiple files as a single user.
You could do something similar by maintaining the file names as a list inside Gatling's session variable, but this session would still not be shared between different users you inject into your scenario.
i have try to read Json file using copy activity and write data in sql server.
my json file available in blob store.
i have set file fromat-JSON format
when i try to import schema i got error-Error occurred when
deserializing source JSON data. Please check if the data is in valid
JSON object format.. Activity ID:2f799221-f037-4f72-8e6c-385778929110
myjsonData
{
"id": "ed0e4960-d9c5-11e6-85dc-d7996816aad3",
"context": {
"device": {
"type": "PC"
},
"custom": {
"dimensions": [
{
"TargetResourceType": "Microsoft.Compute/virtualMachines"
},
{
"ResourceManagementProcessRunId": "827f8aaa-ab72-437c-ba48-d8917a7336a3"
},
{
"OccurrenceTime": "1/13/2017 11:24:37 AM"
}
]
}
}
}
Regards,
Manish
Based on your description and your sample source data, you could import the schema directly,however the column is nested.
If you want to flatten the nested json before you store them into sql server database as rows,you could execute Azure Function Activity before the Copy Activity.
Or you could execute the stored procedure in sql server dataset.
I am having difficulties getting multiple datasets out of my database with RestTemplate. I have many routines that extract a single row, with a format like:
IndicatorModel indicatorModel = restTemplate.getForObject(URL + id,
IndicatorModel.class);
and they work fine. However, if I try to extract a set of data, such as:
Map<String, List<S_ServiceCoreTypeModel>> coreTypesMap =
restTemplate.getForObject(URL + id, Map.class);
this returns values in a
Map<String, LinkedHashMap<>>
format. Is there an easy way to return a List<> or Set<> in the desired format?
Fundamentally the issue is that your Java object model does not match the structure of your json document. You are attempting to deserialize a single json element into a java List. Your JSON document looks like:
{
"serviceCoreTypes":[
{
"serviceCoreType":{
"name":"ALL",
"description":"All",
"dateCreated":"2016-06-23 14:46:32.09",
"dateModified":"2016-06-23 14:46:32.09",
"deleted":false,
"id":1
}
},
{
"serviceCoreType":{
"name":"HSI",
"description":"High-speed Internet",
"dateCreated":"2016-06-23 14:47:31.317",
"dateModified":"2016-06-23 14:47:31.317",
"deleted":false,
"id":2
}
}
]
}
But you cannot turn a serviceCoreTypes into a List, you can only turn a Json Array into a List. For instance if you removed the unnecessary wrapper elements from your json and your input document looked like:
[
{
"name": "ALL",
"description": "All",
"dateCreated": "2016-06-23 14:46:32.09",
"dateModified": "2016-06-23 14:46:32.09",
"deleted": false,
"id": 1
},
{
"name": "HSI",
"description": "High-speed Internet",
"dateCreated": "2016-06-23 14:47:31.317",
"dateModified": "2016-06-23 14:47:31.317",
"deleted": false,
"id": 2
}
]
You should be able to then deserialize THAT into a List< S_ServiceCoreTypeModel>. Alternately if you cannot change the json structure, you could create a Java object model that models the json document by creating some wrapper classes. Something like:
class ServiceCoreTypes {
List<ServiceCoreType> serviceCoreTypes;
...
}
class ServiceCoreTypeWrapper {
ServiceCoreType serviceCoreType;
...
}
class ServiceCoreType {
String name;
String description;
...
}
I'm assuming you don't actually mean database, but instead a restful service as you're using RestTemplate
The problem you're facing is that you want to get a Collection back, but the getForObject method can only take in a single type parameter and cannot figure out what the type of the returned collection is.
I'd encourage you to consider using RestTemplate.exchange(...)
which should allow you request for and receive back a collection type.
I have a solution that works, for now at least. I would prefer a solution such as the one proposed by Ben, where I can get the HTTP response body as a list of items in the format I chose, but at least here I can extract each individual item from the JSON node. The code:
S_ServiceCoreTypeModel endModel;
RestTemplate restTemplate = new RestTemplate();
JsonNode node = restTemplate.getForObject(URL, JsonNode.class);
JsonNode allNodes = node.get("serviceCoreTypes");
JsonNode oneNode = allNodes.get(1);
ObjectMapper objectMapper = new ObjectMapper();
endModel = objectMapper.readValue(oneNode.toString(), S_ServiceCoreTypeModel.class);
If anyone has thoughts on how to make Ben's solution work, I would love to hear it.
How can I modify ajax response before jsTree creation? I would like to access each node ID and add prefix to it. On jsTree page the only clue is this: the function will receive two arguments - the node being loaded & a function". I need to do that before the tree is actually created, to avoid duplicate ID in the document.
"json_data" : {
"ajax" : {
"type": "GET",
"url" : "tree.json"
},
"data" : function(node, func){
//how to use that?
}}
I have expected to get JSON data here, modify it and return? But this will explode.
I have successfully manipulated data using the success callback in the instantiation of the jsTree. In my case, I am parsing XML data returned as JSON from a .NET webmethod. It should work for your case in a similar manner.
"ajax": {
"type": "GET"
"url": "tree.json",
"success": function (x) {
//manipulate string x to change id's here
return x;
}, ...
Another method is to use the "complete" callback function to manipulate the jsTree in its final form. I don't recommend it in your case of duplicate id's, however.