How to converted dataTable from request Spring Boot - java

i'm learning programming and want use DataTables and i have a problem. I don't know how to converted records...
I have code in spring boot
#RequestMapping(path="/seriess", method=RequestMethod.GET)
public Page<SeriesDao> showSeries(#RequestParam(defaultValue="0") int page)
{
Page<SeriesDao> sss = seriesRepository.findAll(new PageRequest(page, 20));
return sss;
}
#RequestMapping("/showSeries")
public ModelAndView model(){
ModelAndView model = new ModelAndView("showSeries");
return model;
}
Next I have json when i go to localhost:8080/seriess, i didn't copy all result (20)
{"content":[{"id":41,"name":"Average Weekly Earnings of All Employees: Total Private in Corpus Christi, TX (MSA)","file":"SMU48185800500000011.csv","cassid":"1d2e556b-031e-4c6f-aec4-981c4e907324","categoryid":3,"datefrom":"2006-12-31","dateto":"2016-09-30","frequency":5,"markers":null,"unit":"$ per Week","feed":"Macroeconomic_And_Major_Markets","createdate":1476567529000,"changedate":1483919401000}........and next 19 records ]
"last":false,"totalPages":25,"totalElements":488,"size":20,"number":0,"sort":null,"first":true,"numberOfElements":20}
This is my java script code. I have to correct convert this data from url, but i don't know how...
$(document).ready( function () {
$('#dataTable').DataTable({
"processing": true,
"serverSide": true,
"ajax": {
"url": "seriess",
"dataSrc" : ""
}
},
"columns": [
{ "data": "id"},
{ "data": "name" },
{ "data": "file" },
{ "data": "cassid" },
{ "data": "categoryid" },
{ "data": "datefrom" },
{ "data": "dateto" },
{ "data": "frequency" },
{ "data": "markers" },
{ "data": "unit" },
{ "data": "feed" },
{ "data": "createdate" },
{ "data": "changedate" }
]
})});

Change
"ajax": {
"url": "seriess",
"dataSrc" : ""
}
}
to
"ajax": {
"url": "/seriess",
"dataSrc" : "content"
}
}

Related

How to handle JsonObject to own Object

Now i take JsonObject from API like this:
Its XML object converted to JsonObject.
"Details": {
"row": [
{
"item": [
{
"name": "Account",
"value": 12521512
},
{
"name": "ACCNO",
"value": 4214
},
{
"name": "Number",
"value": 5436
}
]
},
"item": [
{
"name": "Account",
"value": 5789678
},
{
"name": "ACCNO",
"value": 6654
},
{
"name": "Number",
"value": 0675
}
]
},
But i need convert this object and send like this:
{
"Details": {
"row": [
{
"Account": 12521512,
"ACCNO": 4214,
"Number": 12412421
},
{
"Account": 5789678,
"ACCNO": 6654,
"Number": "0675"
}
]
}
}
I have rows more than 1000, i need faster way to handle.
How to handle, please help me
You could use the JSON-java library to parse your input and transform it to your desired format. Something like this works but you may need to adjust it to your needs:
JSONObject jsonObject = new JSONObject(json); // Load your json here
JSONObject result = new JSONObject("{\"Details\": {\"row\": []}}");
for (Object row : jsonObject.getJSONObject("Details").getJSONArray("row")) {
if (!(row instanceof JSONObject)) continue;
Map<Object, Object> values = new HashMap<>();
for (Object item : ((JSONObject) row).getJSONArray("item")) {
if (!(item instanceof JSONObject)) continue;
values.put(((JSONObject) item).get("name"), ((JSONObject) item).get("value"));
}
result.getJSONObject("Details").getJSONArray("row").put(values);
}
// Now result is in your format

REST-assured | How to get a string value based on matching critera using JSONpath

I need to get count value based on matching critera using REST Assured Jsonpath
I tried the following but its not working :
response().jsonPath().getString("{it.B == '456'}.B1.size()")
JSON :
[{ "A": "123", "A1": [{ "A11": "A111" }, { "A12": "A112" }, { "A13": "A113" }] },
{ "B": "456", "A1": [{ "B11": "B111" }, { "B12": "B112" }, { "B13": "B113" }, { "B14": "B114" }, { "B15": "B115" }] },
{ "C": "456", "A1": [{ "C11": "C111" }, { "C12": "C112" }, { "C13": "C113" }, { "C14": "C114" }, { "C15": "C115" }, { "C16": "C116" }] }
]
Please try the below, it will return 456
response().jsonPath().getString("$.[1].B")

Apache Velocity: remove key/value from json

I have a JSON
{
"Id": "xxx",
"Type": "Transaction.Create",
"Payload": {
"result": 2,
"description": "Pending",
"body": {
"redirect": {
"url": "xxx",
"fields": {
"MD": "8a829449620619e80162252adeb66a39"
}
},
"card": {
"expiryMonth": "1",
"expiryYear": "2033"
},
"order": {
"amount": 1
}
}
}
}
And I want to remove the card info of it like this:
{
"Id": "xxx",
"Type": "Transaction.Create",
"Payload": {
"result": 2,
"description": "Pending",
"body": {
"redirect": {
"url": "xxx",
"fields": {
"MD": "8a829449620619e80162252adeb66a39"
}
},
"order": {
"amount": 1
}
}
}
}
How can I do this with Apache velocity?
What works is:
#set($content = $util.urlEncode($input.json('$')))
#set($new = $content.replaceAll("2033","2055"))
Action=SendMessage&MessageBody={"body": "$new","Event-Signature": "$util.urlEncode($input.params('Event-Signature'))"}
This gives me
{
"Id": "xxx",
"Type": "Transaction.Create",
"Payload": {
"result": 2,
"description": "Pending",
"body": {
"redirect": {
"url": "xxx",
"fields": {
"MD": "8a829449620619e80162252adeb66a39"
}
},
"card": {
"expiryMonth": "1",
"expiryYear": "2050"
},
"order": {
"amount": 1
}
}
}
}
But now I want to remove the card part but it does not work:
#set($content = $util.urlEncode($input.json('$')))
#set($new = $content.delete("$.Payload.body.card"))
Action=SendMessage&MessageBody={"body": "$new","Event-Signature": "$util.urlEncode($input.params('Event-Signature'))"}
what am I doing wrong?
Main goal is transform a mapping template in API Gateway for a webhook. The webhook contains to many information and we want to remove some part of the JSON POST call.
Try using the below
#set($dummy=$content.Payload.remove("card"))

How can I return multiple assets after execution of my drools rule?

I can use kie-workbench rule engine and I created many rules. Everything is working good. But I could not be successful for returning multiple assets. Where is "LoanApplication" in RESPONSE?
My Rule :
package mortgages.mortgages;
import java.lang.Boolean;
import java.lang.Number;
import java.lang.String;
import java.util.Date;
import java.lang.Integer;
//from row number: 1
rule "Row 1 Gdt2"
dialect "mvel"
when
f2 : Applicant( age > 18 )
then
f2.setAge( 18 );
f2.setApproved( true );
Applicant f10 = new Applicant();
f10.setAge( 18 );
insert( f10 );
LoanApplication f12 = new LoanApplication();
f12.setAmount( 20000 );
insert( f12 );
end
if I call above rule by SOAP UI restful: http://localhost:8080/kie-server/services/rest/server/containers/instances/mortgages_1.0.0-SNAPSHOT
REQUEST:
{
"commands": [
{
"insert": {
"object": {
"Applicant": {
"age": 20
}
},
"out-identifier": "t1",
"return-object": true
}
}, {
"insert": {
"object": {
"Applicant": {
"age": 22
}
},
"out-identifier": "t2",
"return-object": true
}
},
{
"fire-all-rules": {}
}
]
}
RESPONSE:
{
"type": "SUCCESS",
"msg": "Container mortgages_1.0.0-SNAPSHOT successfully called.",
"result": {"execution-results": {
"results": [
{
"value": {"mortgages.mortgages.Applicant": {
"age": 18,
"applicationDate": null,
"approved": true,
"creditRating": null,
"name": null
}},
"key": "t1"
},
{
"value": {"mortgages.mortgages.Applicant": {
"age": 18,
"applicationDate": null,
"approved": true,
"creditRating": null,
"name": null
}},
"key": "t2"
}
],
"facts": [
{
"value": {"org.drools.core.common.DefaultFactHandle": {"external-form": "0:73:1097496811:1097496811:73:DEFAULT:NON_TRAIT:mortgages.mortgages.Applicant"}},
"key": "t1"
},
{
"value": {"org.drools.core.common.DefaultFactHandle": {"external-form": "0:74:1887265498:1887265498:74:DEFAULT:NON_TRAIT:mortgages.mortgages.Applicant"}},
"key": "t2"
}
]
}}
}
if you look at :
LoanApplication f12 = new LoanApplication();
f12.setAmount( 20000 );
insert( f12 );
this rule blocked code. I can not see value in RESPONSE like that. How can I do that?
"value": {"mortgages.mortgages.LoanApplication": {
"Amount": 20000...
......
.....
}},
......
To get LoanApplication object in response you have to use getobject method in request payload, like as
{ "commands": [
{
"insert": {
"object": {
"Applicant": {
"age": 20
}
},
"out-identifier": "t1",
"return-object": true
}
}, {
"insert": {
"object": {
"Applicant": {
"age": 22
}
},
"out-identifier": "t2",
"return-object": true
}
},
{
"fire-all-rules": {}
},{
"get-objects":{ "identifier":"f12",
"out-identifier":"result"
}
}]}

How do you map Json structure having type identification inside the node

{
"task": {
"vendorConnectorId": 9901,
"operation": "query",
"objectType": "",
"attributes": {
"q": "SELECT Name FROM Asset where AccountId = '00128000005O5uPAAS'"
}
},
"httpStatusCode": 200,
"resultSet": {
"result": {
"totalSize": 1,
"records": [
{
"attributes": {
"type": "Asset",
"url": "/services/data/v34.0/sobjects/Asset/02i280000007BcpAAE"
},
"Name": "Flight To LA"
}
],
"done": true
}
},
"messages": [],
"startedTime": 1441969739375,
"endTime": 1441969750317
}
I want to map records node via polymorphic de-serialization feature of Jackson but type information is nested inside the record node(attribute node).

Categories