How to pass json data to jasper report using rest - jasper-reports

I am new to jasper. I have created a jasper report using JSON data source and pushed it to server. Is there a way to pass JSON data to the jasper report using rest call? I cannot find any example to follow.

If you have a report that has a json or jsonql query, what you can do is to provide a default value for the JSON_INPUT_STREAM builtin parameter based on the value of a another parameter that you create in the report. Something like this:
<parameter name="JsonData" class="java.lang.String">
</parameter>
<parameter name="JSON_INPUT_STREAM" class="java.io.InputStream">
<defaultValueExpression><![CDATA[new ByteArrayInputStream($P{JsonData}.getBytes("UTF-8"))]]></defaultValueExpression>
</parameter>
<queryString language="json">
<![CDATA[..json query..]]>
</queryString>
Than you'd need to create an input control for the JsonData parameter in the JasperReports Server report. If you have that you can pass a value for JsonData when running the report via REST:
"parameters": {
"reportParameter": [
{
"name": "JsonData",
"value": [
"{..json data..}"
]
}
]
}

Related

How edit attributes in dimension element of IBM Сognos with REST API

I am creating new dimension element in IBM Cognos via REST API. I need to change the attributes of these elements. How can this be done via the REST api?
create element
I found the answer. Attributes are stored as cubes cells. Here's an example of setting attributes for my example.
POST: https://localhost:10005/api/v1/Cubes('%7DElementAttributes_Cars')/tm1.Update
BODY:
[{
"Cells": [
{
"Tuple#odata.bind": [
"Dimensions('}ElementAttributes_Cars')/Hierarchies('}ElementAttributes_Cars')/Elements('Caption')",
"Dimensions('Cars')/Hierarchies('Cars')/Elements('000007')"
]
}
],
"Value": "Chevrolet Niva 2015"
}]

ServiceNow em_event table additional_Info field is returning [object Object]

We are using Rest API via PowerShell (Invoke-RestMethod), in order to insert records in ServiceNow event [em_event] table with a single call, using the web service API.
We successfully inserting events to the em_event table,
but the only problem is with the additional_info field.
For some reason,
The JSON structure of my PowerShell script,
Is causing the output of additional_info, to return as an Object and Not as JSON string.
And as a result,
The values in additional_info not showing properly, but instead as [object Object]:
This is the JSON structure in my PowerShell script:
# Specify request body
$body = #"
{ "records":
[
{
"source":"MyClass",
"event_class":"$AtargetResourceType",
"resource":"$AtargetResourceType",
"node":"$AtargetResourceName",
"metric_name":"$Aname",
"type":"$AsignalType",
"severity":"$Aseverity",
"message_key":"$Aid",
"u_mc_object":"$AtargetResource",
"description":"$Adescription",
"additional_info":"{
'u_mc_object_class':'$AsourceCreatedId',
'u_mc_parameter':'$AmetricName',
'u_mc_parameter_value':'$AmetricValue'
}"
}
]
}
"#
image which you have posted is not opening. but according to your issue below line will return string value for additional_info:
($body|ConvertFrom-Json).records.additional_info
I had the same issue sending the request using Postman, I was sending the request like this:
{ "records":
[
{
"source":"BMC TrueSight",
"type":"Incident from trusight",
"severity":"1",
"description":"This is a test from WEB SERVICE API ERROR",
"additional_info":{
"status":"new",
"description":"This is a descriotion from additional information",
"category":"41",
"subcategory": "test",
"company": "test",
"business_service":"test"
}
}
]
}
and it showed [object][object] in the additional information field, what I did was sent that field as a string like this:
"additional_info": "{\"assignee_group\":\"ETSS\/UNIX99\",\"status\":\"new\",\"description\":\"This is a descriotion from additional information\",\"category\":\"41\",\"subcategory\":\"test\",\"company\":\"test\",\"business_service\":\"
}
You only need to convert the JSON into a string.

Use output from Web Activity call as variable

I'm using ADFv2 to transfer some data. As a part of this operation I need some configuration values to pass into the pipeline.
The config values must be pulled at runtime from a REST service - not as parameters.
I can successfully query the REST service with Web Activity and I can see the output in the debug view.
Now the problem :)
How do I use this output in other activities further in the pipeline?
My Web Activity configuration is like this:
{
"name": "Web1",
"type": "WebActivity",
"policy": {
"timeout": "7.00:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false
},
"typeProperties": {
"url": "https://myazurefunction.azurewebsites.net/api/MyFunction",
"method": "GET",
"headers": {
"Content-Type": "application/json"
}
}
I have tried to access the output after is has executed, but it seems empty:
#activity('Web1').Output
#activity('Web1').output
#string(activity('Web1').Output)
they are all empty. Any suggestions?
Thanks!
I set up an ADF2 and try to get a response.
This works for me:
#string(activity('Post').output)
Have you checked the output in the debugging?
Here is my output:
{
"test": {
"value": 123,
"text": abc
},
"concat": 123abc
}
I use the stored procedure to insert the values into the destination table on a Logical Server.
In ADFv2, you access the output of previous activities using #activity('ActivityName').output.
For the web activity defined, the response from your function should be in JSON format, so you would reference specific JSON values using their attribute names in the response. For example, your defined web activity, named Web1, calls a function that returns a response of:
{
"foo": "bar",
"some": "value"
}
To use the value of foo in a subsequent ADF activity, you would reference #activity('Web1').output.foo. ADFv2 provides multiple type conversion functions, should you need the returned value converted to another type.
If your function is returning an empty JSON response back, you may want to inspect the response from your function using Postman or another tool to ensure you are returning a properly formatted response, and that your function isn't failing for another reason.
Inside your Azure function code, you should be returning a JSON object, along with a success code, similar to return req.CreateResponse(HttpStatusCode.OK, json);.
Also note that if you reference a property of the response and it does not exist, ADF will fail at that point, so you can use an If Condition activity to check for the required values to better handle failures in ADFv2.

Talend read JSON data from tRESTRequest

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/

Add Custom Data Type/Field in Jaydata

How can I add a custom data type in Jaydata wherein I can just add anything on it and have it output in http://localh.ost/blahblah/$metadata ?
Like
$data.Entity.extend("Office", {
Id: { type: "id", key: true, computed: true },
OfficeName: { type: "string", maxLength:50, alternativeName:"office_name" }
});
Like I want to add the alternativeName and have it output in the browser so that when I type the http://localh.ost/blahblah/$metadata, I can see it as one of the fields.
Like:
//other XML output here
<Property MaxLength="50" Name="OffName" Type="Edm.String" alternativeName="office_name"/>
//other XML output here
Right now, I can only see this:
<Property MaxLength="50" Name="OffName" Type="Edm.String" />
So how can I achieve this?
Start the custom attribute name with $ sign