I am using a nested JSON file as mockup data in a ODATA SAPUI5 application, but I cannot access the nested data.
JSON content
[{
"testcase": {
"specification": "SRS PR 28717 – Deposit in Brazilian Reais",
"execution": {
"description": "DESC",
"bca_cn_acct_01": {
"header": {
"section": "Field / Section Name",
"data": "Data to Enter / Value to Select",
"action": "Activity / Check / Comment"
},
"frame": {
"ID": 1,
"title": "Create Account: Initial Screen",
"data": [{
"key": "Contract Start",
"value": "02/16/2000",
"action": ""
}, {
"key": "Contract Manager",
"value": "GH_RAMOSCL",
"action": ""
}, {
"key": "Product",
"value": "BR_IOFTC3",
"action": ""
}, {
"key": "Account Holder",
"value": "GH_IOF_COR",
"action": "Press Enter"
}]
}
}
},
"result": "Teste"
}}]
In my view file, I want to access the data inside the tag, as a list:
<core:View controllerName="sap.ui.demo.MockServer.controller.App" xmlns:core="sap.ui.core" xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="sap.m">
<!-- <List headerText="{i18n>headerText}" id="list" items="{/Meetups}" noDataText="{i18n>noDataText}">
<items>
<ObjectListItem number="{ path: 'EventDate', type: 'sap.ui.model.type.DateTime', formatOptions: { style: 'medium' } }" title="{Title}">
<attributes>
<ObjectAttribute text="{Description}"/>
</attributes>
</ObjectListItem>
</items>
</List>
<Button press="onPressAction" text="{i18n>loadFirstItems}"></Button> -->
<List headerText="{i18n>headerText}" id="list" items="{/Meetups}" noDataText="{i18n>noDataText}">
<items>
<ObjectListItem number="{ path: 'EventDate', type: 'sap.ui.model.type.DateTime', formatOptions: { style: 'medium' } }"
title="{testcase/execution/description}">
<attributes>
<ObjectAttribute text="{specification}"/>
</attributes>
</ObjectListItem>
</items>
</List>
<Table id="table" items="{/Meetups}">
<columns>
<Column width="12em">
<Text text="Field / Section Name"/>
</Column>
<Column minScreenWidth="Tablet" demandPopin="true">
<Text text="Data to Enter / Value to Select"/>
</Column>
<Column minScreenWidth="Tablet" demandPopin="true">
<Text text="Activity / Check / Comment"/>
</Column>
</columns>
<items>
<ColumnListItem>
<cells>
<ObjectIdentifier title="{testcase/execution/bca_cn_acct_01/frame/data/key}" class="sapMTableContentMargin"/>
<!-- <Text text="{testcase/execution/bca_cn_acct_01/bca_dte_event_begin_d}" /> -->
<Text text="{testcase/execution/bca_cn_acct_01/frame/data/value}"/>
</cells>
</ColumnListItem>
</items>
</Table>
<Button press="onPressAction" text="{i18n>loadFirstItems}"></Button>
However, data from fields key and value are not retrieved as list, although they are an array inside the JSON data tag.
I use as base the sample tutorial from SAPUI5 library: https://sapui5.hana.ondemand.com/#docs/guide/7a78f1b707c248fd9ec53dcb5f10814c.html
And below you can find the metadata file I have been using:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<edmx:Edmx Version="1.0"
xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
<edmx:DataServices
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:DataServiceVersion="1.0">
<Schema Namespace="NerdMeetup.Models"
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns="http://schemas.microsoft.com/ado/2006/04/edm">
<EntityType Name="Meetup">
<ComplexType Name="testcase">
<ComplexType Name="execution">
<!-- Create Payment Item -->
<ComplexType Name="bca_cn_acct_01">
<ComplexType Name="header">
<Property Name="section" Type="Edm.String" Nullable="false" />
<Property Name="data" Type="Edm.String" Nullable="false" />
<Property Name="action" Type="Edm.String" Nullable="false" />
</ComplexType>
<ComplexType Name="frame">
<Property Name="ID" Type="Edm.Int32" Nullable="false" />
<Property Name="title" Type="Edm.String" Nullable="false" />
<ComplexType Name="data">
<Property Name="key" Type="Edm.Int32" Nullable="false" />
<Property Name="value" Type="Edm.Int32" Nullable="false" />
<Property Name="action" Type="Edm.Int32" Nullable="true" />
</ComplexType>
</ComplexType>
<Property Name="bca_dte_event_begin_d" Type="Edm.String" Nullable="false" />
<Property Name="bca_dte_orgunit_cnmgt" Type="Edm.String" Nullable="false" />
<Property Name="fspr_prodext_y" Type="Edm.String" Nullable="false" />
<Property Name="bca_dte_bupa_acchold" Type="Edm.String" Nullable="false" />
</ComplexType>
</ComplexType>
<Property Name="specification" Type="Edm.String" Nullable="true" />
</ComplexType>
</EntityType>
<EntityContainer Name="NerdMeetups" m:IsDefaultEntityContainer="true">
<EntitySet Name="Meetups" EntityType="NerdMeetup.Models.Meetup" />
<FunctionImport Name="FindUpcomingMeetups" EntitySet="Meetups" ReturnType="Collection(NerdMeetup.Models.Meetup)" m:HttpMethod="GET" />
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
Any ideas?
Hugs
I guess you can either bind the entire array:
{testcase/execution/bca_cn_acct_01/frame/data/}
Or bind an specific element of the array:
{testcase/execution/bca_cn_acct_01/frame/data/0/key}
You could also use a formatter to receive an array and concatenate all the keys of the array check the
Formatter SAPUI5 documentation
Related
I have two json from two different endpoints, i need to concatenate to convert it into a single valid json. I did it, but the first WSO2 json returns it as a string (firstjson). I would like it to be all a json.
FIRST JSON
{
"first": true,
"second": {
"name": "manoj",
"age": "45"
},
"third": {
"fourth": [
{
"class": "test12",
"salary": "123456"
},
{
"class": "test23",
"salary": "15678"
}
],
"fifth": "hello"
}
}
SECOND JSON
[
{
"item1": "123456",
"item2": "5678"
},
{
"item1": "8976",
"item2": "abcd"
}
]
XML API
<api context="/concat" name="concat" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" url-mapping="/concatenare">
<inSequence>
<call>
<endpoint>
<http method="get" uri-template="http://www.mocky.io/v2/56b2d88c13000057518945d4">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>1</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</call>
<enrich>
<source clone="false" type="body"/>
<target property="first-json" type="property"/>
</enrich>
<log level="custom">
<property expression="get-property('first-json')" name="First json"/>
</log>
<call>
<endpoint>
<http method="get" uri-template="http://www.mocky.io/v2/56b2d87d1300007c518945d3">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>1</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</call>
<log level="custom">
<property expression="get-property('first-json')" name="*********BEFOREEEEEEEE"/>
</log>
<!-- <enrich>
<source clone="false" property="first-json" type="property"/>
<target type="body"/>
</enrich> -->
<payloadFactory media-type="xml">
<format>
<completeJson xmlns="">
<firstjson>$1</firstjson>
<secondjson>$2</secondjson>
</completeJson>
</format>
<args>
<arg evaluator="xml" expression="get-property('first-json')"/>
<arg evaluator="xml" expression="$body"/>
</args>
</payloadFactory>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
<send/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
RESPONSE API
{
"completeJson": {
"firstjson": "{\"first\":true,\"second\":{\"name\":\"manoj\",\"age\":\"45\"},\"third\":{\"fourth\":[{\"class\":\"test12\",\"salary\":\"123456\"},{\"class\":\"test23\",\"salary\":\"15678\"}],\"fifth\":\"hello\"}}",
"secondjson": {
"Body": [
{
"item1": 123456,
"item2": 5678
},
{
"item1": 8976,
"item2": "abcd"
}
]
}
}
}
Where am I wrong ?
Thanks in advance guys
Ok guys,
I solved it, I was wrong with the payloadFactory, the format it had to be of type json.
<payloadFactory media-type="json">
<format>
{
"completeJson" : {
"firstjson" : $1,
"secondjson" : $2
}}
</format>
<args>
<arg expression="get-property('first-json')" />
<arg expression="$body" />
</args>
</payloadFactory>
thanks anyway guys :)
my json is as follows
"values": [
{
"purchase": {
"name":"bags"
},
"weekSpend": [
{
"weekStartDate": 20181105,
"spend":100
},
{
"weekStartDate": 20181112,
"spend":200
}
]
},
{
"purchase": {
"name":"shoes"
},
"weekSpend": [
{
"weekStartDate": 20181105,
"spend":100
},
{
"weekStartDate": 20181112,
"spend":200
}
]
},
]
I want to displayed the grid where rows are
productname and (columns by weekstartdate)
I followed the technique provided in How to show column at Crosstab even the data is absent
However the productname are listed in row but the column are showing only first column.
my data set is as follows
<queryString language="jsonql">
<![CDATA[]]>
</queryString>
<field name="productName" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="product.name"/>
<fieldDescription><![CDATA[product.name]]></fieldDescription>
</field>
<field name="weekStartDate" class="java.lang.String[]">
<property name="net.sf.jasperreports.jsonql.field.expression" value="weekSpend.weekStartDate"/>
</field>
<group name="activityDateGroup">
<groupExpression><![CDATA[$F{weekStartDate}]]></groupExpression>
</group>
my crossdata datasource is as follows
<crosstabDataset isDataPreSorted="true">
<dataset>
<datasetRun subDataset="crossTabDataSet" uuid="e7b27508-8a48-4785-a48e-c646249df9a9">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonQLDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("..values(#size > 0).*")]]></dataSourceExpression>
</datasetRun>
</dataset>
</crosstabDataset>
and bucketexpression is on weekstartdate.
With these using JsonQL still only the first column is displayed
How do i get list of column based on weekstardate from iterating from rootnode.
i am using jasper studio 6.5.
Thanks
Anjana.
There is an invalid field mapping: weekStartDate to java.lang.String[], that is not supported in JSONQL.
Instead you could have this subDataset expression:
<datasetRun subDataset="crossTabDataSet" uuid="e7b27508-8a48-4785-a48e-c646249df9a9">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonQLDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("..values(#size > 0)..weekSpend.*")]]></dataSourceExpression>
</datasetRun>
with these field mappings:
<field name="productName" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="^{2}.purchase.name"/>
</field>
<field name="weekStartDate" class="java.lang.Integer">
<property name="net.sf.jasperreports.jsonql.field.expression" value="weekStartDate"/>
</field>
I have defined a api in wso2 esb and it calls two internal APIs through recepient list and which are passing json responses as follows.(sample responses)
{
"name": "api1",
"response": "success",
"status": "1"
}
and
{
"name": "api2",
"response": "unsuccess",
"status": "2"
}
I need to pass the response by aggregating both of these responses as a single response. I red about payloadfactory and able to construct aggregated response. But i need to aggregate whatever the responses coming from these 2 apis and generate response as one single json object and pass by including both of these responses as follows
{
"response1": {
"name": "api1",
"response": "success",
"status": "1"
},
"response2": {
"name": "api2",
"response": "unsuccess",
"status": "2"
}
}
so how can a accomplish with WSO2ESB. I'm using latest version of ESB.
I have created three APIs and aggregated the API responses using Clone ,Below is my API which is used for aggregating responses of two API endpoints
<api xmlns="http://ws.apache.org/ns/synapse" name="aggregateResponse" context="/aggregate">
<resource methods="POST">
<inSequence>
<clone id="aggr">
<target>
<sequence>
<call>
<endpoint>
<http method="GET" uri-template="http://localhost:8280/getresponse1"/>
</endpoint>
</call>
<log>
<property name="Logger1" expression="json-eval($.)"/>
</log>
</sequence>
</target>
<target>
<sequence>
<call>
<endpoint>
<http method="GET" uri-template="http://localhost:8280/getResponse2"/>
</endpoint>
</call>
<log>
<property name="Logger1" expression="json-eval($.)"/>
</log>
</sequence>
</target>
</clone>
<payloadFactory media-type="json">
<format>{"responses":{ "name":"$1","response":"$2","status":"$3"}}</format>
<args>
<arg evaluator="json" expression="$.name"/>
<arg evaluator="json" expression="$.response"/>
<arg evaluator="json" expression="$.status"/>
</args>
</payloadFactory>
<loopback/>
</inSequence>
<outSequence>
<property name="res" scope="default">
<ResponseDetail xmlns=""/>
</property>
<aggregate id="aggr">
<completeCondition>
<messageCount min="-1" max="-1"/>
</completeCondition>
<onComplete expression="$body//responses" enclosingElementProperty="res">
<payloadFactory media-type="json">
<format>{"response1":$1 ,"response2":$2}</format>
<args>
<arg evaluator="json" expression="$.ResponseDetail.responses[0]"/>
<arg evaluator="json" expression="$.ResponseDetail.responses[1]"/>
</args>
</payloadFactory>
<send/>
</onComplete>
</aggregate>
</outSequence>
</resource>
</api>
API 1:
<api xmlns="http://ws.apache.org/ns/synapse" name="response1" context="/getresponse1">
<resource methods="GET">
<inSequence>
<payloadFactory media-type="json">
<format>{ "name": "api1", "response": "success", "status": "1"}</format>
<args/>
</payloadFactory>
<respond/>
</inSequence>
</resource>
</api>
API 2:
<api xmlns="http://ws.apache.org/ns/synapse" name="response2" context="/getResponse2">
<resource methods="GET">
<inSequence>
<payloadFactory media-type="json">
<format>{ "name": "api2", "response": "unsuccess", "status": "2"}</format>
<args/>
</payloadFactory>
<respond/>
</inSequence>
</resource>
</api>
Well, this is where enrich mediator becomes handy. Please try this out. I have not tested this since I am not doing WSO2 related stuffs now. But your feedback is warmly welcome. The pseudo code is something like this.
<call>
<endpoint>
<http method="GET" uri-template="http://www.mocky.io/v2/some-ep"/>
</endpoint>
</call>
<enrich>
<source type="body" clone="true"/>
<target type="property" property="first-json"/>
</enrich>
<call>
<endpoint>
<http method="GET" uri-template="http://www.mocky.io/v2/another-ep"/>
</endpoint>
</call>
<enrich>
<source type="property" property="first-json" clone="true"/>
<target action="sibling" xpath="//"/>
</enrich>
</respond>
I am learning solr (5.5.0) and running in a standalone mode.
Here is the solr-data-config.xml:
<dataConfig>
<dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://127.0.0.1/DBN" user="root" password="root"/>
<document>
<entity name="planexample" query="select * from plan where userid=60 limit 3">
<field column="planid" name="id" />
<field column="userid" name="userid" />
<field column="planname" name="planname" />
<field column="del" name="del" />
</entity>
</document>
</dataConfig>
And I add fields accordingly into managed-schema:
<field name="userid" type="int" indexed="true" stored="true" required="true" multiValued="true"/>
<field name="planname" type="string" indexed="true" stored="true" required="true" multiValued="true"/>
<field name="del" type="int" indexed="true" stored="true" required="true" multiValued="true"/>
<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" />
But when I do query on the webpage of solr, for example, ip:8983/solr/corename/select?q=del%3A1&wt=json&indent=true or ip:8983/solr/corename/select?q=userid%3A60&wt=json&indent=true, results only show the id except userid,planname,del, how to make those fields visible in results? And what does the score field mean in results?
One example of results:
{
"responseHeader": {
"status": 0,
"QTime": 1,
"params": {
"indent": "true",
"q": "del:1",
"_": "1461050814466",
"wt": "json"
}
},
"response": {
"numFound": 10,
"start": 0,
"maxScore": 0.90468985,
"docs": [
{
"id": "985963",
"score": 0.90468985
},
{
"id": "1033572",
"score": 0.90468985
},
{
"id": "1763216",
"score": 0.90468985
}
]
}
}
You need to provide a fl parameter, to get all stored fields,
do &fl=*, or a comma seperated list of fields you want i.e.
&fl=id,userid,planname,del for example.
The two jsons i need to concatenate to convert it into a single valid json are :
{
"first": true,
"second": {
"name": "manoj",
"age": "45"
},
"third": {
"fourth": [{
"class": "test12",
"salary": "123456"
},
{
"class": "test23",
"salary": "15678"
}
],
"fifth": "hello"
}
}
and
[{
"item1": "123456",
"item2": "5678"
},
{
"item1": "8976",
"item2": "abcd"
}]
Is it possible to concatenate these two without using any jquery. I need something related to wso2 esb code. I tried using enrich and other mediators but no luck so far.
You can concat the jsons using WSO2 ESB Payload Factory mediator as follows,
<api xmlns="http://ws.apache.org/ns/synapse" name="ConcatAPI" context="/concat">
<resource methods="GET">
<inSequence>
<call>
<endpoint>
<http method="GET" uri-template="http://www.mocky.io/v2/56b2d88c13000057518945d4"/>
</endpoint>
</call>
<enrich>
<source type="body" clone="true"/>
<target type="property" property="first-json"/>
</enrich>
<log level="custom">
<property name="First json" expression="get-property('first-json')"/>
</log>
<call>
<endpoint>
<http method="GET" uri-template="http://www.mocky.io/v2/56b2d87d1300007c518945d3"/>
</endpoint>
</call>
<payloadFactory media-type="xml">
<format>
<completeJson xmlns="">
<firstjson>$1</firstjson>
<secondjson>$2</secondjson>
</completeJson>
</format>
<args>
<arg evaluator="xml" expression="get-property('first-json')"/>
<arg evaluator="xml" expression="$body"/>
</args>
</payloadFactory>
<property name="messageType" value="application/json" scope="axis2"/>
<send/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
Note that i have retrieved your jsons from mocked services from mocky.io web site.
Thanks.