Something wrong with my XML? - extjs

i'm parsing an xml with my extjs but it returns only one of the five components.
only the first one of the five components.
Ext.regModel('Card', {
fields: ['investor']
});
var store = new Ext.data.Store({
model: 'Card',
proxy: {
type: 'ajax',
url: 'xmlformat.xml',
reader: {
type: 'xml',
record: 'investors'
}
},
listeners: {
single: true,
datachanged: function(){
Ext.getBody().unmask();
var items = [];
store.each(function(rec){
alert(rec.get('investor'));
});
and my xml file is:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<investors>
<investor>Active</investor>
<investor>Aggressive</investor>
<investor>Conservative</investor>
<investor>Day Trader</investor>
<investor>Very Active</investor>
</investors>
<events>
<event>3 Month Expiry</event>
<event>LEAPS</event>
<event>Monthlies</event>
<event>Monthly Expiries</event>
<event>Weeklies</event>
</events>
<prices>
<price>$0.5</price>
<price>$0.05</price>
<price>$1</price>
<price>$22</price>
<price>$100.34</price>
</prices>
</root>
wen i run the code only "Active" comes out. . . .
i know that i'm doing something wrong but i'm not sure what....
please help . . . . .

Every thing was fine execpt that my xml format should be like this:
Active
3 Month Expiry
$0.5
Aggressive
LEAPS
$0.05
Conservative
Monthlies
$1
Day Trader
Monthly Expiries
$22
Very Active
Weeklies
$100.34
<?xml version="1.0" encoding="UTF-8"?>
<main>
<root>
<investor>Active</investor>
<event>3 Month Expiry</event>
<price>$0.5</price>
</root>
<root>
<investor>Aggressive</investor>
<event>LEAPS</event>
<price>$0.05</price>
</root>
<root>
<investor>Conservative</investor>
<event>Monthlies</event>
<price>$1</price>
</root>
<root>
<investor>Day Trader</investor>
<event>Monthly Expiries</event>
<price>$22</price>
</root>
<root>
<investor>Very Active</investor>
<event>Weeklies</event>
<price>$100.34</price>
</root>
</main>

You need to visit the sencha.com tutorial on how to use XML with a grid.
XML Grid Sample
You should take not of how to properly structure your XML so that it can be consumed by a data store.

The Ext XML grid needs to be configured to look for the repeating elements to map to each record in your store/grid. You had it configured for investors, of which there is only 1. Then you mapped a field for investor and it is just grabbing the first one that it encounters for the "column" of that "row".
The repeating element for your "rows" in the grid should be investor, not investors.
Change: record: 'investors'
to: record: 'investor'

Related

Mule 4 dynamic queries in the Database Connector

In my flow in Mule 4 I am trying to query a database for specific data.
For example I want to run a query like this:
SELECT * FROM mulesoft WHERE plant = CCCNNB;
The thing is both plant and CCNNB need to be dynamic. They will come through an API request. I can handle the value to be dynamic, but I get empty results whenever I try to make the field dynamic.
I first create a variable which stores the json from the request:
set-variable value="#[payload]" doc:name="Set Variable" doc:id="8ed26865-d722-4fdb-9407-1f629b45d318" variableName="SORT_KEY"/>
Request looks like this:
{
"FILTER_KEY": "plant",
"FILTER_VALS": "CCNNB"
}
Afterwards in the db connector I configure the following:
<db:select doc:name="Select" doc:id="13a66f51-2a4e-4949-b383-86c43056f7a3" config-ref="Database_Config">
<db:sql><![CDATA[SELECT * FROM mulesoft WHERE :filter_key = :filter_val;]]></db:sql>
<db:input-parameters ><![CDATA[#[{
"filter_val": vars.SORT_KEY.FILTER_VALS,
"filter_key": vars.SORT_KEY.FILTER_KEY
}]]]></db:input-parameters>
Replacing :filter_key with plant works but as soon as I try to make it dynamic I get nothing in the response. It does not fail though, response code is 200 but I get nothing inside it.
How can I make this work?
You can directly use the stored variables in the query itself.
Query Should be an expression in DataWeave.
#["SELECT * FROM $(vars.table) WHERE $(vars.SORT_KEY.FILTER_KEY) = :filter_val"]
<db:select config-ref="Database_Config">
<db:sql><![CDATA[#["SELECT * FROM $(vars.table) WHERE $(vars.SORT_KEY.FILTER_KEY) = :filter_val"]]]></db:sql>
<db:input-parameters ><![CDATA[#[{
"filter_val": vars.SORT_KEY.FILTER_VALS
}]]]>
</db:input-parameters>
</db:select>
There is another way also to read values from payload to build a dynamic query as below
#["SELECT * FROM mulesoft
WHERE " ++ vars.SORT_KEY.FILTER_KEY ++ " = '" ++ vars.SORT_KEY.FILTER_VALS ++ "'"]
Below is the XML that is created for this, as a POC
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:os="http://www.mulesoft.org/schema/mule/os"
xmlns:salesforce="http://www.mulesoft.org/schema/mule/salesforce"
xmlns:db="http://www.mulesoft.org/schema/mule/db"
xmlns:xml-module="http://www.mulesoft.org/schema/mule/xml-module"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd
http://www.mulesoft.org/schema/mule/os http://www.mulesoft.org/schema/mule/os/current/mule-os.xsd">
<http:listener-config name="HTTP_Listener_config1"
doc:name="HTTP Listener config"
doc:id="6d5de64b-1355-4967-9352-4b324f02c7ad">
<http:listener-connection host="0.0.0.0"
port="8081" />
</http:listener-config>
<db:config name="Database_Config" doc:name="Database Config"
doc:id="d5c4d49c-aef3-4d4a-a7b5-470da3354127">
<db:my-sql-connection host="localhost"
port="3306" user="root" password="admin123" database="Mysql" />
</db:config>
<flow name="testFlow"
doc:id="8cfea1b0-d244-40d9-989c-e136af0d9f80" initialState="started">
<http:listener doc:name="Listener"
doc:id="265e671b-7d2f-4f3a-908c-8065a5f36a07"
config-ref="HTTP_Listener_config1" path="test" />
<set-variable value="#[payload]" doc:name="Set Variable"
doc:id="265a16c5-68d4-4217-8626-c4ab0a3e38e5" variableName="SORT_KEY" />
<db:select doc:name="Select"
doc:id="bdf4a59c-0bcc-46ac-8258-f1f1762c4e7f"
config-ref="Database_Config">
<db:sql><![CDATA[#["SELECT * FROM mulesoft.mulesoft WHERE " ++ vars.SORT_KEY.FILTER_KEY ++ " = '" ++ vars.SORT_KEY.FILTER_VALS ++ "'"]]]></db:sql>
</db:select>
<ee:transform doc:name="Transform Message"
doc:id="72cbe69f-c52e-4df9-ba5b-dd751990bc08">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
</ee:message>
</ee:transform>
</flow>
</mule>
Explanation of the Flow
I am using the payload that is in Question
Seting a variable name "SORT_KEY", value of this varibale is complete payload that we receive.
then creating a dynamic query inside the Db connector
using transform message sending the data as response, that we received from DataBase
So, there are several issues here. One, the creation of the sql statement.
You can do DW inside the DB:SELECT component if you want, as shown by previous answers. Either the
#["SELECT * FROM myTable" ++ vars.myWhere]
OR
#["SELECT * FROM myTable $(vars.myWhere)"]
work.
The problem you will run into is that DataSense doesn't like this. Without the literal text for the column names, DataSense can't figure out what columns to retrieve so it raises an error "Unable to resolve value for the prameter: sql". This leaves an error in your code, which always gives me angst. I wish Mulesoft would resolve this problem.
BTW, if you do dynamic SQL, you should STILL use input parameters for each value to avoid SQL injections.
I have an "Idea" posted here to fix the bogus error: https://help.mulesoft.com/s/ideas#0872T000000XbjkQAC

WSO2 ESB File connector 2 search returns empty response

I use file connector 2 provided by WSO2 ESB (v 5.0.0) to search for a file in the given directory. isFileExist function returns true but when I search for the same file, it returns empty response. Is this a bug or am I missing something?
This is my code
<fileconnector.isFileExist>
<source>file:///home/test/abc.OUT</source>
</fileconnector.isFileExist>
<log level="full"/>
<fileconnector.search>
<source>file:///home/test/</source>
<filePattern>abc.OUT</filePattern>
<recursiveSearch>false</recursiveSearch>
</fileconnector.search>
<log level="full"/>
This is the response I get
To: , WSAction: mediate, SOAPAction: mediate, MessageID: urn:uuid:2391811e-5c83-4b98-a801-a60fe55b6fd0, Direction: request, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><fileExist>true</fileExist></soapenv:Body></soapenv:Envelope> {org.apache.synapse.mediators.builtin.LogMediator}
To: , WSAction: mediate, SOAPAction: mediate, MessageID: urn:uuid:2391811e-5c83-4b98-a801-a60fe55b6fd0, Direction: request, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><ns:result xmlns:ns="http://org.wso2.esbconnectors.FileConnector"/></soapenv:Body></soapenv:Envelope> {org.apache.synapse.mediators.builtin.LogMediator}
I get the same result when I use .*\.txt file pattern in search too.
Please help, TIA
Can you try "abc.out" for file pattern in the search operation?
<filePattern>abc.out</filePattern>

Camel - which pattern to use in order to complete xml with values from other services

I have an xml similar to the following which has some element composed by an url. That url is another webservice which contains another xml. What I need to do is completing my xml with information from the webservice, and I would like to achieve that with camel. Here goes the example:
Initial xml
<root>
<level11>Level1.txt</level1>
<level12>
<level21>http://someservice/11</level21>
<level21>http://someservice/12</level21>
</level12>
<level13>
<level22>http://someservice/21</level22>
<level22>http://someservice/22</level22>
</level13>
</root>
http://someservice is returning an xml which i have to replace into original xml. For example
http://someservice/11 returns
<someservice>
<test>11</test>
</someservice>
http://someservice/12 returns
<someservice>
<test>12</test>
</someservice>
http://someservice/21 returns
<someservice>
<test>21</test>
</someservice>
http://someservice/22 returns
<someservice>
<test>22</test>
</someservice>
my final xml would be:
<root>
<level11>Level1.txt</level1>
<level12>
<level21>
<someservice>
<test>11</test>
</someservice>
</level21>
<level21>
<someservice>
<test>12</test>
</someservice>
</level21>
</level12>
<level13>
<level22>
<someservice>
<test>21</test>
</someservice>
</level22>
<level22>
<someservice>
<test>22</test>
</someservice>
</level22>
</level13>
</root>
So my question is what is the best pattern I should use to achieve this result?
This seems to fit the content enrichment EIP. This EIP will allow you to append and expand you original message based on the output of other services. See more about this at the Apache Camel site by reading the Content Enrichment EIP documentation.

FreeMarker inline template (load from database) in Smooks not interpreted

All,
I try to load the FreeMarker template from database in the Smooks configuration file and use the build-ins INTERPRET to parse the string as template. However, the output is exactly the template I stored in the database.
The following is part of the Smooks configuration file:
....
<resource-config selector="hs:TravelerProfile">
<resource>org.milyn.delivery.DomModelCreator</resource>
</resource-config>
<db:executor executeOnElement="hs:TravelerProfile" datasource="StagingDS">
<db:statement>select freeMarker_template from template_lookup where agencyid='111';
</db:statement>
<db:resultSet name="mytemplate" />
</db:executor>
<ftl:freemarker applyOnElementNS="www.travel.com" applyOnElement="TravelerProfile">
<ftl:template>
< !--
<#assign templateSource = r"${mytemplate[0].freeMarker_template}">
<#assign inlineTemplate = [templateSource, "myInlineTemplate"]?interpret>
<#inlineTemplate/>
-- >
</ftl:template>
</ftl:freemarker>
.....
The template I stored in the database is like following:
<#ftl ns_prefixes={"D":"www.hhs.gov/travel"}>
<?xml version="1.0" encoding="UTF-8"?>
<po:PoHeadersInterfaceCollection xmlns:po="https://www.travel.com/xmlns/financial/po112007.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://www.travel.com/xmlns/financial/po112007.xsd">
<po:PoHeadersInterface>
<po:interfaceSourceCode>VendorName</po:interfaceSourceCode>
<po:poLinesInterfaceCollection>
<po:PoLinesInterface>
<po:PoDistributionsInterfaceCollection>
<po:PoDistributionsInterface>
<po:destinationOrganizationId>${TravelerProfile.TravelerOfficeCode}
</po:destinationOrganizationId>
</po:PoDistributionsInterface>
</po:PoDistributionsInterfaceCollection>
</po:PoLinesInterface>
</po:poLinesInterfaceCollection>
</po:PoHeadersInterface>
</po:PoHeadersInterfaceCollection>
====================================
For some reason, the output is exactly the above template itself. "${TravelerProfile.TravelerOfficeCode}" has not been evaluated! Please help!!!
Thank you!!!
Agnes
Sine mytemplate[0].freeMarker_template returns the template source code itself (or at least I assume that), and since you are using a raw string literal (r"..."), the source code of your template will be literally ${mytemplate[0].freeMarker_template}, which is then evaluated by ?interpret to the template source code. The corrected template would be:
<#assign inlineTemplate = [mytemplate[0].freeMarker_template, "myInlineTemplate"]?interpret>
<#inlineTemplate/>
which can be also written as:
<#([mytemplate[0].freeMarker_template, "myInlineTemplate"]?interpret) />
or if you don't need the "myInlineTemplate" template name:
<#mytemplate[0].freeMarker_template?interpret />

Windows 7 Mobile Silverlight : Linq to XML issue

I have a XML Document:
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>blahblah</title>
<subtitle>blahblah.</subtitle>
<link href="blahblah"/>
<link href="blahblah"/>
<updated>blahblah</updated>
<author>
<name>blahblah</name>
</author>
<id>blahblah</id>
<entry>
<title>blahblah</title>
<content type="html"><![CDATA[“some text.”]]></content>
</entry>
</feed>
I want to get the entry nodes content information, here's my code:
var xmlTreeVal = XDocument.Load("myxml.xml");
var returnVal = from item in xmlTreeVerse.Descendants("feed").Elements("entry")
select new VerseModel
{
Verse = item.Element("content").Value
};
The xml document is loading fine (as i could tell via debugging), but it keeps throwing a 'No sequential items found' error. How do I find the "content" nodes info?
Whenever your XML has a namespace (indicated by the xmlns attribute) you must reference the elements by also referencing their namespace. This is done by concatenating the namespace to the element name.
Also, you used xmlTreeVal but then reference xmlTreeVerse - it's probably not the problem but it's an inconsistency in the code you presented.
Try this:
var ns = xmlTreeVerse.Root.GetDefaultNamespace();
var returnVal = from item in xmlTreeVerse.Descendants(ns + "feed").Elements(ns + "entry")
select new
{
Verse = item.Element(ns + "content").Value
};

Resources