How to iterate through results array and construct Response array by adding carValue and bikeValue into id ("C_05"-"B_08"/"C_07"/"B_06") of the Response array and keep the same desc as description.
JSON Payload Request:
{"results": [
{
"desc": "Blind",
"carValue": "05",
"bikeValue": "08"
},
{
"desc": "Deaf",
"carValue": "09",
"bikeValue": "10"
},
{
"desc": "Oxygen",
"carValue": "07"
},
{
"desc": "carbon",
"bikeValue": "06"
}]
}
final Response should be:
{
"Response" : [
{
"id" : "C_05"-"B_08",
"description" : "Blind"
},
{
"id" : "C_09"-"B_10",
"description" : "Deaf"
},
{
"id": "C_07",
"description": "Oxygen"
},
{
"id": "B_06",
"description": "carbon"
}]
}
You can use the iterate, aggregate and script mediators, as I show you in this proxy.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="proxyIterateJson"
startOnLoad="true"
statistics="disable"
trace="disable"
transports="http,https">
<target>
<inSequence>
<payloadFactory media-type="json">
<format>
{"results": [
{
"desc": "Blind",
"carValue": "05",
"bikeValue": "08"
},
{
"desc": "Deaf",
"carValue": "09",
"bikeValue": "10"
},
{
"desc": "Oxygen",
"carValue": "07"
},
{
"desc": "carbon",
"bikeValue": "06"
}]
}
</format>
<args/>
</payloadFactory>
<iterate xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
attachPath="//jsonObject"
expression="//jsonObject/results"
id="it1"
preservePayload="true">
<target>
<sequence>
<property expression="$body//jsonObject/results/carValue"
name="carValue"
scope="default"
type="STRING"/>
<property expression="$body//jsonObject/results/bikeValue"
name="bikeValue"
scope="default"
type="STRING"/>
<property expression="$body//jsonObject/results/desc"
name="description"
scope="default"
type="STRING"/>
<script language="js">var carValue = mc.getProperty("carValue");
var bikeValue = mc.getProperty("bikeValue");
var desc = mc.getProperty("description");
var concatValue;
if(carValue == null || carValue == "") {
concatValue = "B_" + bikeValue;
} else if(bikeValue == null || bikeValue == "" ){
concatValue = "C_" + carValue;
}else {
concatValue = "C_"+ carValue + "-" + "B_" + bikeValue;
}
print("Value concatenado: "+ concatValue );
mc.setProperty("concatValue", concatValue);
mc.setPayloadJSON({"result":{"id" : concatValue,"description" : desc}});</script>
<log>
<property expression="json-eval($.result.id)" name="JSON-Payload"/>
</log>
<loopback/>
</sequence>
</target>
</iterate>
</inSequence>
<outSequence>
<property name="res" scope="default">
<ns:Response xmlns:ns="www.response.org"/>
</property>
<aggregate id="it1">
<completeCondition>
<messageCount max="-1" min="-1"/>
</completeCondition>
<onComplete enclosingElementProperty="res" expression="$body//result">
<log level="custom" separator=",">
<property expression="json-eval($.)" name="OUPUTSECUENSE"/>
</log>
<send/>
</onComplete>
</aggregate>
</outSequence>
<faultSequence/>
</target>
<description/>
</proxy>
This is the response
{"Response":
{"result":[
{"id":"C_09-B_10","description":"Deaf"},
{"id":"C_05-B_08","description":"Blind"},
{"id":"C_07","description":"Oxygen"},
{"id":"B_06","description":"carbon"}
]}}
You can also use custom or payloadFactory mediator to generate the Json response
https://docs.wso2.com/display/ESB500/Writing+a+WSO2+ESB+Mediator
Related
This is my steps:
The Json code:
"features": [
{
"name": "size",
"selected": null,
"values": [
{
"value": "40",
"label": "40",
},
{
"value": "41",
"label": "41",
}
]
},
{
"label": "color",
"selected": "gray",
"values": [
{
"value": "gray",
"label": "gray"
},
{
"value": "black",
"label": "black",
}
]
}
]
Step2: define state
constructor(props) {
super(props);
this.state ={selectedDropDownValue:[]};
}
step3:
main render:
render{
return(
{this.printPickers()}
);
}
and
printPickers(){
const listItems = data.map((obj,index) =>
<Item picker key={'mykey1' + index}>
<Picker
selectedValue={(this.state.selectedDropDownValue[obj.label]) ?this.state.selectedDropDownValue[obj.label] : obj.selected}
onValueChange={(itemValue, itemIndex, itemName) =>this.pickerChange(itemIndex,itemValue,obj.name)}
>
{
obj1.values.map( (v)=>{
return <Picker.Item key={'mykey2' + index} label={v.label} value={v.value} />
})
}
</Picker>
</Item>
);
return (<View>{listItems}</View>);
}
and finally:
pickerChange(itemIndex,itemValue,itemName){
this.setState({
selectedDropDownValue: Object.assign(this.state.selectedDropDownValue, {[itemName]: itemValue})
});
}
My problem I can not change options of each pickers by touching them but with console.log(this.state.selectedDropDownValue), I get right data.
My problem I can not change options of each pickers by touching them but with console.log(this.state.selectedDropDownValue), I get right data.
There is some mismatch in json data. Either both should have a key label or name.
So suppose both items have key as label then you need to update your pickerChange function call like this:
this.pickerChange(itemIndex,itemValue,obj.label)
I started using react-admin and is basically works fine. However I have some trouble using the ReferenceField.
The REST API I'm calling returns e.g. the following JSON data:
/language
{
"language": [
{
"id": 0,
"name": "Language #0"
},
{
"id": 1,
"name": "Language #1"
},
{
"id": 2,
"name": "Language #2"
},
{
"id": 3,
"name": "Language #3"
}
]
}
/myreferences
{
"myreferences": [
{
"id": 0,
"langauge": {
"id": 0,
"name": "Language #0"
},
"name": "My reference #0"
},
{
"id": 1,
"langauge": {
"id": 1,
"name": "Language #1"
},
"name": "My reference #1"
},
{
"id": 2,
"langauge": {
"id": 2,
"name": "Language #2"
},
"name": "My reference #2"
}
]
}
And that's how map this in react-admin.
export const LanguageList = props => (
<List
title="Languages"
sort={{ field: "name", order: "ASC" }}
filters={<LanguageFilter/>}
{...props}
>
<Datagrid>
<NumberField source="id" label="ID" />
<TextField source="name" label="Name" />
<EditButton />
</Datagrid>
</List>
);
export const MyReferenceList = props => (
<List
title="My References"
sort={{ field: "name", order: "ASC" }}
filters={<MyReferenceFilter />}
{...props}
>
<Datagrid>
<NumberField source="id" label="ID" />
<TextField source="name" label="Name" />
<ReferenceField source="langauge.id" reference="language" label="Language">
<TextField source="name" />
</ReferenceField>
<EditButton />
</Datagrid>
</List>
);
My problem is that the references are shown correctly but when I click on the column for the referenced language name react-admin sorts by the language's ID instead of its name.
What do I need to adapt so that sorting by name is working?
The <ReferenceField> component accepts a sortBy prop, which specifies the field to use for sorting instead of the source. So in your case, you can write:
<ReferenceField source="language.id" sortBy="language.name" reference="language" label="Language">
<TextField source="name" />
</ReferenceField>
This is explained in the React-admin documentation:
https://marmelab.com/react-admin/Fields.html#referencefield
I have a custom checkbox
<checkbox v-model="form.terms_accepted" />
The true/false value toggles fine
{
"first_name": "",
"last_name": "", "username": "",
"email": "", "terms_accepted": true
}
How do I validate for a true value?
at the moment I my validation rule is.
terms_accepted: {
required
},
You can use a simple function:
terms_accepted: {
checked: value => value === true
}
terms_accepted: {
checked: sameAs(true)
}
works for latest vuelidate as of today:
"#vuelidate/core": "^2.0.0",
"#vuelidate/validators": "^2.0.0",
I'm new in datatables and sorry for my bad english.
I really need your help to help solve my problem.
So, my code is all in one page :
$( function () {
var oTable;
function fnFormatDetails( nTr ) {
var aData = oTable.fnGetData(nTr);
sOut = "<?php foreach($this->m_rumah_sakit->getStyleAndCount(280)->result() as $style){
echo $style->keterangan; ?>
<br /> 1. Yes : ( <i><?php echo ($style->yes)?$style->yes:'0'; ?> Ulasan </i>)
<br /> 2. No : ( <i><?php echo ($style->no)?$style->no:'0'; ?> Ulasan</i> )
<br /> 3. Not Sure : ( <i><?php echo ($style->not_sure)?$style->not_sure:'0'; ?> Ulasan</i> ) <br /><?php } ?>";
return sOut;
}
$(document).ready ( function() {
oTable = $('#tSortable').dataTable({
"bProcessing": true,
"bServerSide": true,
"aaSorting": [[1,'asc']],
"oLanguage": {"sProcessing": "<img src=" + vars.loader + ">"},
//"sAjaxSource": "../details_col.php",
"sAjaxSource" : base + "cms-ajax-data",
"fnServerParams" : function ( aoData ) {
aoData.push(
{ "name": "p", "value" : "" },
{ "name": "hRating", "value" : "hospital" }
,{ "name": "c", "value" : vars.column }
,{ "name": "iC", "value" : vars.indexColumn }
,{ "name": "t", "value" : vars.table }
,{ "name": "w", "value" : vars.where }
,{ "name": "imp", "value" : vars.implode }
);
},
"aoColumnDefs": [{"bSortable":false,"bSearchable":false, "sClass": "hidden", "aTargets":[1]}]
});
$('#tSortable tbody td img').live('click',function(){
var nTr = this.parentNode.parentNode;
if(this.src.match('details_close')){
this.src = "..//details_open.png";
oTable.fnClose(nTr);
}else
this.src = "../details_close.png";
oTable.fnOpen(nTr,fnFormatDetails(nTr),'details');
}
});
});
And all works like charms! the only problem is : how i can get variable aData[2] in PHP script?
I mean, how to call it like this in my PHP code :
foreach($this->m_rumah_sakit->getStyleAndCount("+aData[2]+")->result();
Hope you understand what I mean. Thanks for any advise.
Must any URL of RSS resource end with ".xml" when used in Worklight?
For example: http://www.youku.com/user/rss/id/24645394
I tried to save the above as an XML file, then place it in my localhost. It works. However, the below code doesn't work... I get the following invocation result.
Do you you have solution about my case?
{
"errors": [
"Premature end of file.",
"Failed to parse the payload from backend (procedure: HttpRequest)"
],
"info": [
],
"isSuccessful": false,
"responseHeaders": {
"Accept-Ranges": "bytes",
"Age": "0",
"Cache-Control": "no-store, no-cache, must-revalidate",
"Connection": "close",
"Content-Length": "0",
"Content-Type": "text\/html; charset=utf-8",
"Date": "Mon, 07 Apr 2014 16:24:45 GMT",
"Server": "Varnish",
"X-Cache": "Miss from 1.w.b28"
},
"responseTime": 2452,
"statusCode": 404,
"statusReason": "Unknown virtual host",
"totalTime": 2465,
"warnings": [
]
}
News.xml
<?xml version="1.0" encoding="UTF-8"?>
<wl:adapter name="News"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:wl="http://www.worklight.com/integration"
xmlns:http="http://www.worklight.com/integration/http">
<displayName>News</displayName>
<description>News</description>
<connectivity>
<connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
<protocol>http</protocol>
<domain>www.youku.com</domain>
<port>80</port>
</connectionPolicy>
<loadConstraints maxConcurrentConnectionsPerNode="2" />
</connectivity>
<procedure name="getStories" />
<procedure name="getStoriesFiltered" />
</wl:adapter>
News-impl.js
function getStories(interest) {
path = getPath(interest);
var input = {
method : 'get',
returnedContentType : 'xml',
path : path
};
return WL.Server.invokeHttp(input);
}
function getStoriesFiltered(interest) {
path = getPath(interest);
var input = {
method : 'get',
returnedContentType : 'xml',
path : path,
transformation : {
type : 'xslFile',
xslFile : 'filtered.xsl'
}
};
return WL.Server.invokeHttp(input);
}
function getPath(interest) {
if (interest == undefined || interest == '') {
interest = '/user/rss/id/24645394/';
}else {
interest = '/user/rss/id/'+interest;
}
return interest;
}
filtered.xsl
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:h="http://www.w3.org/1999/xhtml">
<xsl:output method="text"/>
<xsl:template match="/">
{
'Items': [
<xsl:for-each select="rss/channel/item">
{
'title': '<xsl:value-of select="title"/>',
'link': '<xsl:value-of select="link"/>'
},
</xsl:for-each>
]
}
</xsl:template>
</xsl:stylesheet>
add host header:
var input = {
method : 'get',
returnedContentType : 'xml',
path : path,
headers: {
"Host":"www.youku.com"
}
};