im using karate framework to test some site, but one call to the endpoints is like this: https://urlbase/index?id=60&filters[start_date]=Fri%20Nov%2018%202022%2010:14:59%20GMT-0300&filters[end_date]=Sat%20Nov%2019%202022%2023:59:59%20GMT-0300
And i have problems with the filters[...] i don't know how to do that :(
I have this query def:
* def query = {id: 60, filters[start_date]:'Fri%20Nov%2018%202022%2010:14:59%20GMT-0300', filters[end_date]:'Sat%20Nov%2019%202022%2023:59:59%20GMT-0300'}
But the request url shows: GET https://urlbase/index?id=60&filters=%7Bstart_date%3D%2C+end_date%3D%7D
`
with no brackets.
And i want my GET url looks like this: https://urlbase/index?id=60&filters[start_date]=Fri%20Nov%2018%202022%2010:14:59%20GMT-0300&filters[end_date]=Sat%20Nov%2019%202022%2023:59:59%20GMT-0300
I tried this and it seems to work fine:
* url 'https://httpbin.org/anything'
* param id = 60
* param filters[start_date] = 'Fri Nov 18 2022 10:14:59 GMT-0300'
* param filters[end_date] = 'Sat Nov 19 2022 23:59:59 GMT-0300'
* method get
You can look at the response and confirm the server handles the request correctly:
{
"args": {
"filters[end_date]": "Sat Nov 19 2022 23:59:59 GMT-0300",
"filters[start_date]": "Fri Nov 18 2022 10:14:59 GMT-0300",
"id": "60"
},
"data": "",
"files": {},
"form": {},
"headers": {
"Accept-Encoding": "gzip,deflate",
"Host": "httpbin.org",
"User-Agent": "Apache-HttpClient/4.5.13 (Java/17.0.4.1)",
"X-Amzn-Trace-Id": "Root=1-6377b983-6bfc4696374f7d08239de823"
},
"json": null,
"method": "GET",
"origin": "X.X.X.X",
"url": "https://httpbin.org/anything?filters[start_date]=Fri+Nov+18+2022+10%3A14%3A59+GMT-0300&filters[end_date]=Sat+Nov+19+2022+23%3A59%3A59+GMT-0300&id=60"
}
Related
I have a JSON String:
{
06-2020={
ma01={
0={duur=Dag, aantalVoertuigen=2, tijd=14: 06, naamHuurder=K, prijs=70 },
1={duur=Dag, aantalVoertuigen=2, tijd=14: 08, naamHuurder=H, prijs=70 },
2={duur=Dag, aantalVoertuigen=2, tijd=14: 08, naamHuurder=H, prijs=70 },
3={duur=Dag, aantalVoertuigen=2, tijd=14: 08, naamHuurder=H, prijs=70 },
Aantal=4
}
},
05-2020={
hallo={auto=ja, naam=ja },
za30={hallo=ja, naam=ja }
}
}
I need to get the 06-2020 and the 05-2020 out of it.
I tried using JSONobject. But that only works with one layer.
Thanks in advance
I have a customer info with orders in Elastic Search in the following format
{
"_index": “customer_domain_r4",
"_type": “CustomerData”,
"_id": "6fff6ce8-e792-4047-b636-a1dda0aa2b72",
"_version": 173,
"_score": 3.551258,
"_source": {
“first”: "John",
“last”: "Doe",
“dateOfBirth”: null,
"primaryPhone": "6154525131",
“customerOrders”: [
{
“orders”: [
{
“orderNumber": 1,
“orderName": “Grocery”,
"recordVersion": 1,
"createdDateTimeGmt": "May 09, 2018 03:19:11 PM",
"deletedDateTimeGmt": "May 12, 2018 08:28:42 PM",
"createdSessionTokenId": "PUWzJmipCIyvciMDEr3IfhXuV3Gx",
"updatedSessionTokenId": "1234567890",
"lastUpdatedDateTimeGmt": "May 12, 2018 08:28:48 PM",
“orderType”: “Online”
"id": "8e2973e3-b43b-4430-b6d7-7c24846e9bba"
},
{
“orderNumber": 2,
“orderName": “Medications”,
"recordVersion": 1,
"createdDateTimeGmt": "May 09, 2018 03:19:11 PM",
"deletedDateTimeGmt": null,
"createdSessionTokenId": "PUWzJmipCIyvciMDEr3IfhXuV3Gx",
"updatedSessionTokenId": "1234567890",
"lastUpdatedDateTimeGmt": "May 12, 2018 08:28:48 PM",
“orderType”: “Offline”
"id": "8e2973e3-b43b-4430-b6d7-7c2665e9bba"
}
]
}
Now my requirement is to fetch only orders of a certain type for a given customer id. The query i ran
{"index":"customer_domain_r4","type":"CustomerData"}
{"query":{"bool":{"must":[{"match":{"id":"6fff6ce8-e792-4047-b636-a1dda0aa2b72"}},{"nested":{"path":"customerOrders","query":{"bool":{"must":[{"match":{"customerOrders. orderType":"Online"}}]}}}}]}},"_source":{"includes":["customerOrders"],"excludes":[]}}
The above query returns all the orders of the customer because the criteria looks for any customer which has an order of type online. I am looking for the query to return only orders of customer 6fff6ce8-e792-4047-b636-a1dda0aa2b72 of type online.
Is there a way i can directly add criteria for the includes section.
If not i have to filter this in the java middle tier section
How can I use Solrj to query Solr using the following api:
http://localhost:8983/solr/admin/zookeeper?detail=true&path=%2Fconfigs%2Fmy-search%2Fdataimport.properties
the above api gives the content of the dataimport.properties file.
{
"znode": {
"path": "/configs/my-search/dataimport.properties",
"prop": {
"version": 186,
"aversion": 0,
"children_count": 0,
"ctime": "Sun Oct 16 10:24:04 UTC 2016 (1476613444895)",
"cversion": 0,
"czxid": 479,
"ephemeralOwner": 0,
"mtime": "Fri Mar 24 09:48:50 UTC 2017 (1490348930211)",
"mzxid": 31451,
"pzxid": 479,
"dataLength": 111
},
"data": "#Fri Mar 24 09:48:50 UTC 2017\nname.last_index_time=2017-03-24 09\\:48\\:49\nlast_index_time=2017-03-24 09\\:48\\:49\n"
},
"tree": [
{
"data": {
"title": "dataimport.properties",
"attr": {
"href": "admin/zookeeper?detail=true&path=%2Fconfigs%2Fmy-search%2Fdataimport.properties"
}
}
}
]
}
btw, my Solr is configured in cloud mode.
Given that your Solr is running in Cloud mode the file /configs/my-search/dataimport.properties is into Zookeeper.
SolrJ does not have native API to easily read from Zookeeper.
To read into the Zookeeper I suggest to use use Apache Curator Framework
String dataPath = "/configs/my-search/dataimport.properties";
String connectionString = "zookeeper-ensemble:2181";
CuratorFramework client = CuratorFrameworkFactory.newClient(connectionString, new ExponentialBackoffRetry(1000, 3));
client.start();
byte[] barray = client.getData().forPath(dataPath);
if (barray != null) {
String data = new String(barray);
System.out.println(data);
}
I'm trying to get some financial data from yahoo finance using java / spring RestTemplate.
Suppose I need the data for IBM, the link would be something like this:
https://query1.finance.yahoo.com/v10/finance/quoteSummary/IBM?formatted=true&modules=incomeStatementHistory%2CcashflowStatementHistory%2CbalanceSheetHistory%2CincomeStatementHistoryQuarterly%2CcashflowStatementHistoryQuarterly%2CbalanceSheetHistoryQuarterly%2Cearnings
which is a nice formatted JSON with all the data I need:
{
"quoteSummary": {
"result": [
{
"cashflowStatementHistoryQuarterly": {
"cashflowStatements": [
{
"maxAge": 1,
"endDate": {
"raw": 1459382400,
"fmt": "2016-03-31"
},
"netIncome": {
"raw": -5490000,
"fmt": "-5.49M",
"longFmt": "-5,490,000"
},
"depreciation": {
"raw": 16849000,
"fmt": "16.85M", ... etc
But when I try to open the same link using RestTemplate:
using a code like:
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<String>response = restTemplate.getForEntity(url, String.class);
The result I'm getting back in response is very different, it looks like this:
<200 OK,{"quoteSummary":{"result":[{}],"error":null}},{X-YQL-Host=[pprd3-node7511-lh2.manhattan.ir2.yahoo.com], X-Content-Type-Options=[nosniff], X-Yahoo-Request-Id=[6s0s3nlbqhlls], Cache-Control=[max-age=1, stale-while-revalidate=15], Content-Type=[application/json; charset=utf-8], Vary=[Origin], Content-Length=[45], Date=[Mon, 08 Aug 2016 19:00:12 GMT], Age=[2], Server=[ATS], Via=[http/1.1 media-ncache-api14.prod.media.ir2.yahoo.com (ApacheTrafficServer [cMsSfW]), http/1.1 media-ncache-api15.prod.media.ir2.yahoo.com (ApacheTrafficServer [cMsSf ]), http/1.1 media-router-api3.prod.media.ir2.yahoo.com (ApacheTrafficServer [cMsSfW]), https/1.1 r07.ycpi.loa.yahoo.net (ApacheTrafficServer [cMsSfW])], Strict-Transport-Security=[max-age=0], Connection=[keep-alive], Y-Trace=[BAEAQAAAAACPmeCQTRIz3QAAAAAAAAAAOEHjlsK9d9kAAAAAAAAAAAAFOZQGmKa_AAU5lAap7rIUoHdnAAAAAA--]}>
Any idea how can I get the same result I'm getting in the browser?
Thank you
I need some help on using elemMatch in spring data to query data in mongodb and retrieve results from mongodb.
I want to retrieve results for a particular testRun say testRun=1
I have the following data in mongodb:
[ {
"testMethod": "initialization",
"testCase": "com.harish.test.TestNGRest.OrganisationGetTest",
"build": 1,
"ranNumberofTimes": 2,
"failed": 0,
"success": 2,
"testRuns": [
{
"testMethod": "initialization",
"testCase": "com.harish.test.TestNGRest.OrganisationGetTest",
"branchName": "branch_1",
"testRun": 1,
"success": 1,
"fail": 0,
"timetorun": 0,
"cases": [
{
"caseId": 1,
"status": "success",
"failreason": null,
"startDate": "Fri May 27 14:41:22 EDT 2016",
"endDate": "Fri May 27 14:41:22 EDT 2016"
}
],
"startDate": "Fri May 27 14:41:22 EDT 2016",
"endDate": "Fri May 27 14:41:22 EDT 2016"
},
{
"testMethod": "initialization",
"testCase": "com.harish.test.TestNGRest.OrganisationGetTest",
"branchName": "branch_1",
"testRun": 2,
"success": 1,
"fail": 0,
"timetorun": 1,
"cases": [
{
"caseId": 1,
"status": "success",
"failreason": null,
"startDate": "Fri May 27 14:41:49 EDT 2016",
"endDate": "Fri May 27 14:41:49 EDT 2016"
}
],
"startDate": "Fri May 27 14:41:49 EDT 2016",
"endDate": "Fri May 27 14:41:49 EDT 2016"
}
]
In mongo console i used the following command and got the results:
db.test.find({"testRuns.testRun":1},{"testRuns":{"$elemMatch":{"testRun":1}}}).pretty()
I got the results for my requirement in mongo console.
The real question comes here, I used spring data in to retrieve the results in my java code.
return mongoTemplate.find(BasicQuery.query(Criteria.where("testRuns.testRun").is(testRun).andOperator(Criteria.where("testRuns").elemMatch(Criteria.where("testRun").is(testRun)))),Test.class, COLLECTION_NAME);
However, i'm not able to retrieve the results for a particular test run. Can someone please help me resolve this issue.
Thank you.
You don't need $elemMatch if you would like to get "testRuns.testRun" = 1. There is no second condition. Please refer the below statement in the mongo reference document link.
"Since the $elemMatch only specifies a single condition, the $elemMatch expression is not necessary, and instead you can use the following query:"
db.survey.find(
{ "results.product": "xyz" }
)
https://docs.mongodb.com/manual/reference/operator/query/elemMatch/
I have tested with the below code with the data given in the post. It works fine.
Please make sure that the testRun variable is defined as Integer in Java code. If it is of other data type, the query wouldn't return result.
query.addCriteria(Criteria.where("testRuns.testRun").is(testRun));
mongoOperations.find(query, Stack.class);