tRestClient Talend with dynamic URL and paramters from DB returns null - json

I'm trying to use Talend from a REST web service and by passing parameters that come from a DB.
I̶ ̶a̶m̶ ̶t̶r̶y̶i̶n̶g̶ ̶t̶o̶ ̶l̶i̶n̶k̶ ̶t̶P̶o̶s̶g̶r̶e̶s̶q̶l̶I̶n̶p̶u̶t̶ ̶c̶o̶m̶p̶o̶n̶e̶n̶e̶t̶ ̶t̶o̶ ̶t̶h̶e̶ ̶t̶R̶e̶s̶t̶ ̶c̶o̶m̶p̶o̶n̶e̶n̶t̶ ̶a̶n̶d̶ ̶t̶o̶ ̶s̶e̶e̶ ̶h̶o̶w̶ ̶t̶o̶ ̶p̶a̶s̶s̶ ̶D̶B̶ ̶r̶o̶w̶s̶ ̶v̶a̶l̶u̶e̶ ̶i̶n̶ ̶t̶h̶e̶ ̶U̶R̶L̶,̶ ̶b̶u̶t̶ ̶i̶t̶s̶ ̶s̶e̶e̶m̶s̶ ̶t̶h̶a̶t̶ ̶t̶R̶E̶S̶T̶ ̶d̶o̶e̶s̶ ̶n̶o̶t̶ ̶a̶c̶c̶e̶p̶t̶ ̶t̶h̶i̶n̶g̶s̶ ̶l̶i̶k̶e̶ ̶t̶h̶i̶s̶.̶
T̶h̶i̶s̶ ̶i̶s̶ ̶w̶a̶h̶t̶ ̶I̶ ̶d̶i̶d̶ ̶u̶n̶t̶i̶l̶ ̶t̶h̶i̶s̶ ̶t̶i̶m̶e̶ ̶:̶
̶t̶P̶o̶s̶g̶r̶e̶s̶q̶l̶I̶n̶p̶u̶t̶ ̶x̶x̶x̶x̶x̶x̶ ̶t̶R̶E̶S̶T̶ ̶-̶-̶-̶>̶ ̶t̶E̶x̶t̶r̶a̶c̶t̶J̶S̶O̶N̶F̶i̶e̶l̶d̶s̶ ̶-̶-̶-̶>̶ ̶t̶M̶a̶p̶ ̶-̶-̶-̶>̶ ̶t̶P̶o̶s̶g̶r̶e̶s̶q̶l̶O̶u̶t̶p̶u̶t̶
I verified that the DB component returns data below:
I updated the job as this:
The Schema of tRESTClient is :
And I used globalMap to pass the values from the database:
The used URL is : "URL/search/"+ (String)globalMap.get("row1.hashtag")
But when I see the results, I found it used the "null" value to request the server.

All I needed is to use a tFlowToIterate component to iterate each row, so that we will able to access the input data extracted from DB and set a dynamic URL.
For example as I have before, the job must look like this :
BBin --main(row1)--> tFlowToITerate --iterate--> tREST ---> tExtractJSONFields ---> tMap ---> DBout
On tRest, we can set a dynamic URL like:
"SOME_URL/otherpath/"+(String)globalMap.get("row1.columnName")

Related

JMeter - How to change the JSON value while executing script in JMeter

I am recording a Receipt-Accept scenario(Unique Number) in JMeter. Once the recording was done Jmeter fetching some values from DB like the below:
POST data:
{
"pItemID": 8793120,
"pShipHeaderID": 41343933,
"pHeaderID": 37123507,
"pLineID": 45338365,
"pRCVTransID": 113927590,
"pOrgCode": "E90",
"pRelnum": null
}
this will be unique for each receipt. I don't know which value will come for the next receipt. How can I handle this?
POST data:
{
"pItemID": 8793120,
"pShipHeaderID": 41343933,
"pHeaderID": 37123507,
"pLineID": 45338365,
"pRCVTransID": 113927590,
"pOrgCode": "E90",
"pRelnum": null
}
[no cookies]
I expect the values present under "POST data" should dynamically change in the run time.
You could use the random function to generate a random value and use the same
{
"pItemID": ${__Random(0,7)},
}
Please check the link bellow for more information on Jmeter functions and variables
https://jmeter.apache.org/usermanual/functions.html#__Random

Do not show JSON data in columns

The software I'm using saves a copy of the data that I think is json in an extra-different table when I do records in the database.
What I want to do is to be able to query the json data contained in the DATASETS column separately.
I'm using SQL 2012 as my server
This is the query I tried so far:
SELECT TOP 1 IND, SNAPSHOTDATE, DATASETS, USERNAME, OWNERFORM
FROM TBLSNAPSHOTS
CODE RESULT:
105 2018-09-14 02:59:34.000 { "Datasets": [{"Name": "TBLSTOKLAR","Lines": [{"IND": "102","STOKNO": "","MALINCINSI": "TITIZ PLASTIK BUYUK KASIK 10 ADET","STOKKODU": "8691262708050","ANABIRIM": "102","BIRIMEX": "102","ALTSEVIYE": "","KRITIKSEVIYE": "","USTSEVIYE": "","DEPOSEVIYESI": "True","URETICI": "","AYLIKVADE": "0","SERINO": "","DEPO": "1","STOKGRUBU": "","GARANTI": "0","PRIM": "0","IPTAL": "False","STOKTIPI": "0","STOKTAKIP": "0","TEMINYERI": "1","RAFOMRU": "0","RESIM": "","KALAN": "0","REZERV": "0","KOD1": "","KOD2": "","KOD3": "","KOD4": "","KOD5": "","KOD6": "","KOD7": "","KOD8": "","KOD9": "","KOD10": "","TAKSITSAYISI": "0","ISTIHBARAT": "","FIYATYOK": "","DELETED": "","ALISFIYATI": "0","ESKIALISFIYATI": "0","SONALISTARIHI": "","SONSATISTARIHI": "","KARTINACILMATARIHI": "14.09.18 ı. 02:57:58","DEVIRIND": "","MALIYET": "1","KDVGRUBU": "1","AKTIF": "False","ISCILIKIND": "0","ISCILIKBIRIMIND": "0","ISCILIKACIKLAMA": "","ISCILIKSTOKKODU": "","ALISFIYATIDEGISMETARIHI": "","STATUS": "1","DALISFIYATI": "","APB": "","OIV": "0","KARORANI": "0","OTV": "0","ISK": "0","STOKGRUPTANIMI": "","ISKSATISFIYATI2": "0","ISKSATISFIYATI3": "0","ALISKDVORANI": "18","ALISISKORANI": "","SIPARISALINMASIN": "False","SIPARISVERILMESIN": "False","P1": "","P2": "","P3": "","SATISKOSULU": "","DEFAULTALISFIYATI": "","DEFAULTALISFIYATIDEGISMESTARIHI": "","KDVGRUBUT": "","HEDEFSATISFIAYTI": "","KURUMISKONTOSU": "","TICARIISKONTO": "","ITSBILDIRIMI": "False","MAXISKORANI": "","IMALATCISATISFIYATI": "","DKUR": "1","ACILSEVK": "False","SOGUKSEVK": "False","ICMIKTAR": "","TICARISEKIL": "","MAXISKTUTAR": "","TAXE": "","KOD11": "","DAPB": "","IKINCIEL": "","ETICARET": "","STOKNEVI": "0","OTVORANSAL": "True","POZ": "","YAZARKASA": "False","KOD12": "","KOD13": "","KOD14": "","KOD15": "","KOD16": "","KOD17": "","KOD18": "","KOD19": "","KOD20": "","KOD21": "","UID": "{0DE71D73-E447-45B0-BF6A-1D312DBAFDD2}"}]}]} ADMIN frmEdtStok```
In SQL 2012 - no, you can't directly query the JSON. In SQL 2016 they added functions to let you do this:
https://learn.microsoft.com/en-us/sql/t-sql/functions/json-query-transact-sql?view=sql-server-2017
But if you need to stay on 2012 you are limited to String parsing it (don't do this), or writing/finding a CLR function which parses it using .Net code and returns the results
If you simply must do it quickly there are some hackey solutions to parse it like so: https://www.red-gate.com/simple-talk/sql/t-sql-programming/consuming-json-strings-in-sql-server/ but don't expect it to work smoothly with complex json

What is the json body in post request in order to fetch all rows from an operation list with key?

I have defined a list for operational data in yang model as:
list listener-state {
key “listener-name”;
config false;
description
“common statistics for given listener (i.e sent messages)”;
uses listener-state-info;
…
}
I use opendaylight api (org.opendaylight.yangtools.yang.data.codec.gson.JsonParserStream) which will convert the json body in request to org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode, in order to finally generate the XML rpc for confd server.
In my case, I want to fetch all rows from this operation list, then I try to make the json as :
“command”: {“service” : {“server” : {“listener-state” : {}}}},
I will get exception that : “Input is missing some of the keys of listener-state”
Then I can add the key value to the json body :
“command”: {“service” : {“server” : {“listener-state” : {“listener-name”: “first”}}}},
This case, I can only get one row. I also try to leave the key value as blank:
“command”: {“service” : {“server” : {“listener-state” : {“listener-name”: “”}}}},
Then the response will be all key values instead of all rows. So now my question is what the json will be in order to get all rows in the list without knowing the key values ?
This should be feasible since I figure out XML request can do that. But I can't figure out what the matching json will be.
Thanks.
I did bunch of investigation. Unfortunately, I don't think there is a way to fetch the whole table

Retrieving media upload in controller from array dynamically

I am using Laravel 5.1 and I am using Illuminate\Http\Request instance for accessing sent file requests, but I can't seem to find the correct way to access the media element. I can access all other values in the object.
Here is the JSON data format I am using:
{"_method":"PUT",
"topic":"1 test",
"description":"1 test",
"media_description":"1 test",
"old_parts":
{"part-1":
{"sub_header":"test 2",
"text_field":"test 2 ",
"article_id":"18",
"media":{}},
"part-2":
{"sub_header":"test 3 ",
"text_field":"test 3",
"article_id":"18",
"media":{}}
},
"published":"1",
"media":{}
}
I access media in controller using two foreach loops, one loop is for database collection and other is for form content. I can use following method for accessing media elements.
if ($file = $request->file('media-' . $running_number)) {...}
But it decreases readability by huge amount as I should name the fields f.e. as media-1, media-2, ... and not access them using foreach loop like I do with everything else.
So is there a way to access file with foreach loop variable?
f.e. something like this
foreach($input['old_parts'] as $old_part) {
if ($old_part->hasFile('media')) { ... }
}
If I use the lines I typed the function returns a FatalThrowableError : Call to a member function hasFile() on array.
Or should I just use something like
$request->file('old_parts[part-'.$x.'][media]');
To access the file input and use custom variable to count the index? The problem is just that I can't figure out how to go inside multiple levels in JSON using file, as either old_parts['..']['..'] and old_parts['part-1']->media don't seem to return anything (return null).

What's the best way to send in multiple coordinates in a JSON to RethinkDB in order to create an r.polygon?

I'm using an Express server with RethinkDB, and I want to send in multiple coordinates into my 'locations' table on RethinkDB and create an r.polygon(). I understand how to do the query via RethinkDB's data explorer , but I'm having trouble figuring out how to send it via JSON from the client to the server and insert it through my query there.
I basically want to do this:
r.db('places').table('locations').insert({
name: req.body.name,
bounds: r.polygon(req.body.bounds)
})
where req.body.bounds looks like this:
[long, lat],[long, lat], [long, lat]
I can't send it in as a string because then it gets read as one single input instead of three arrays. I'm sure there's a 'right in front of me' way, but I'm drawing a blank.
What's the best way to do this?
Edit: To clarify, my question is, what should my JSON look like and how should it be received on my server?
This is what RethinkDB wants in order to make a polygon:
r.polygon([lon1, lat1], [lon2, lat2], [lon3, lat3], ...) → polygon
As per the suggestion, I've added in r.args() to my code:
r.db('places').table('locations').insert({
name: req.body.name,
bounds: r.polygon(r.args(req.body.bounds))
})
Edit
Ok, I was dumb and had a typo in one of my coordinates!
Sending it as an array of arrays and wrapping it in r.args() on the server side works.
What you need is r.args to unpack the array into arguments for r.polygon. https://www.rethinkdb.com/api/javascript/args/
With assumption that req.body.bounds is:
[[long, lat],[long, lat], [long, lat]]
And you are submit a raw JSON string from client.
You first need to decode the JSON payload, and get the bounds field, wrap it with args as following:
var body = JSON.parse(req.body)
r.db('places').table('locations').insert({
name: req.body.name,
bounds: r.polygon(r.args(body.bounds))
})