I am using an Xpath Filter to filter out some incoming events.
This is my sample input xml. I need to filter by the value of fieldC, by allowing events that have a fieldC value of 1,2,3,6 or 7.
<?xml version="1.0" encoding="UTF-8"?>
<add>
<doc>
<field name="fieldA">453.97</field>
<field name="fieldB">278.25</field>
<field name="fieldC">3</field>
<field name="fieldD">Agent</field>
<field name="fieldE">Mobile Site</field>
<field name="fieldF">Cancel</field>
<field name="fieldG">2015-09-14T13:17:21.000Z</field>
</doc>
</add>
Xpath Tried:
/add/doc/field[#name='fieldC']/text()
/add/doc/field[#name='fieldC']
<int:chain input-channel="channelIn" output-channel="channelOut">
<int-xml:xpath-filter id="filterEvents" match-value="3" match-type="exact">
<int-xml:xpath-expression expression="/add/doc/field[#name='fieldC']/text()" />
</int-xml:xpath-filter>
</int-xml:xpath-filter>
</int:chain>
Filter by match-type 'exact' works, but I am not able to get the same working with regex.
Regex Tried: /^(1|2|3|6|7)$/
Any help would be appreciated.
Your regex has bad syntax; lose the /s...
match-value="^(1|2|3|6|7)$" match-type="regex"
...works fine for me.
Related
I have a XML FIle which is shown below--
<ROOT>
<account name="ABC" code="XX">
<row>
<field name="ID">7650987</field>
<field name="Length">00:02:37</field>
<field name="Verif">6064625</field>
</row>
<row>
<field name="ID">7651474</field>
<field name="Length">00:01:08</field>
<field name="Verif">6065064</field>
</row>
<row>
<field name="ID">7651105</field>
<field name="Length">00:00:42</field>
<field name="Verif">6064737</field>
</row>
</account>
I need to extract the "code="XX"" based on the Verif value.
I am able to grab the Verif value using Xpath & then I tried reaching root using Parent syntax like,
/ROOT/account/row/field[#name='ID' and text()="7650987"]/parent::*
Above expression is returning blank.
How do I change the same?
First, your XML ROOT tag is not closed. Your XML should finish with
</ROOT>. No xpath would work till you fix the malformed xml. When you close it, your attempted solution would not be blank anymore, although it won't be correct: /ROOT/account/row/field[#name='ID' and text()="7650987"]/parent::*:
This means return "The parent of a 'field' that has name of 'ID' and text of '7450978'", which would be a whole block of XML:
<row>
<field name="ID">7650987</field>
<field name="Length">00:02:37</field>
<field name="Verif">6064625</field>
</row>
Now, what you need is: "The code value of an 'account' that has a child 'row/field' with name of 'ID' and text of '7450978'"
This can be translated as:
//account[row/field/#name="ID" and row/field/text()="7650987"]/#code
I tested it in online XPATH tester and works.
Try ending your xml ROOT
<ROOT>
<account name="ABC" code="XX">
<row>
<field name="ID">7650987</field>
<field name="Length">00:02:37</field>
<field name="Verif">6064625</field>
</row>
<row>
<field name="ID">7651474</field>
<field name="Length">00:01:08</field>
<field name="Verif">6065064</field>
</row>
<row>
<field name="ID">7651105</field>
<field name="Length">00:00:42</field>
<field name="Verif">6064737</field>
</row>
</account>
</ROOT>
This XPath,
/ROOT/account[row/field[#name="ID"]="7650987"]/#code
will return the #code attribute of the account element which has a row/field element with an #name attribute value of "ID" and string value of "7650987", as requested.
how do i can search multiple index content in spring data solr showcase?
just now i only can search "name".
for example how do i can search "companyNo"?.
thanks in advance
sample xml of indexed in solr:
<?xml version="1.0" encoding="UTF-8"?>
<add>
<doc>
<field name="id">1051879H_15082014_00003457</field>
<field name="name">BEST MEGALINK SDN. BHD.</field>
<field name="entityName"></field>
<field name="companyNo">1051879-H</field>
<field name="noticeType">RMAT_N_C</field>
<field name="noticeDate">15/08/2014</field>
<field name="repNames"></field>
<field name="repNames"></field>
<field name="repNames"></field>
<field name="repICs"></field>
<field name="repICs"></field>
<field name="repICs"></field>
<field name="format">PDF</field>
<field name="folder">15082014</field>
<field name="pages">2</field>
</doc>
</add>
Other fields which need to be searched, needs to be added as part of schema.xml.
For example, the fields like the following needs to be added as part schema.xml:
<field name="entityName" type="text_string" indexed="true" stored="true"/>
<field name="companyNo" type="text_string" indexed="true" stored="true"/>
<field name="noticeType" type="text_string" indexed="true" stored="true"/>
I created a module to show related Purchase Orders from projects:
After clicking the Compras (Purchases) button a custom tree view is shown with the currency_id field:
Is there a way to show the symbol of the currency instead of the name? Something like you would do for example using Django: currency_id.symbol. Even better, I want to drop the currency_id field and prepend the currency symbol in the total amount, is that possible? Something like S/. 336.30 in the amount_total field.
Here's my tree view:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
....
....
<record id="purchase_order_project_tree" model="ir.ui.view">
<field name="name">purchase.order.tree</field>
<field name="model">purchase.order</field>
<field name="arch" type="xml">
<tree string="Compras"
colors="grey:state=='cancel';blue:state in ('wait','confirmed');red:state in ('except_invoice','except_picking')">
<field name="name" string="Reference"/>
<field name="date_order" />
<field name="partner_id"/>
<field name="company_id" groups="base.group_multi_company" widget="selection"/>
<field name="currency_id" />
<field name="amount_total" />
<field name="state"/>
</tree>
</field>
</record>
....
....
</data>
</openerp>
You can add a field called currency_symbol in your module (py) that gets the currency symbol when the currency changues with an on_changue to the currency. So you bring that field to the view, you cant directly do it from the XML.
When you click on the that button to get the tree get listed, you can override the "name_get" method of "Currency" and fetch the "currency symbol" instead of name. For this you can pass a flag in the context to limit this modification specific to your module only.
Hope this helps!!.
I am trying to apply some filters in my tree view. And all was going fine until I tried to apply filters based on user.id
My XML code looks like this:
<record model="ir.ui.view" id="view_generic_request_search">
<field name="name">generic_request.search</field>
<field name="model">generic.request</field>
<field name="arch" type="xml">
<search string="Search Request">
<filter icon="terp-mail-message-new" string="My Requests" name="my_requests_filter" domain="[('requestor','=',user.id)]" />
<filter icon="terp-mail-message-new" string="Requests I'm responsible" name="request_im_responsible_filter" domain="[('responsible_name','=',user.id)]" />
<filter icon="terp-mail-message-new" string="Requests I own" name="requests_i_own_filter" domain="[('owner','=',user.id)]" />
<separator />
<filter icon="terp-mail-message-new" string="Denied Requests" name="denied_requests_filter" domain="[('state','=','denied')]"/>
<filter icon="terp-mail-message-new" string="Authorized Requests" name="authorized_requests_filter" domain="[('state','=','authorized')]"/>
<filter icon="terp-mail-message-new" string="Confirmed Requests" name="confirmed_requests_filter" domain="[('state','=','confirmed')]"/>
<separator/>
<group expand="0" string="Group By...">
<filter string="Requested by" domain="[]" context="{'group_by' : 'requestor'}" />
<filter string="Responsible person" domain="[]" context="{'group_by' : 'responsible_name'}" />
<filter string="Status" domain="[]" context="{'group_by': 'state'}"/>
</group>
</search>
</field>
</record>
All filters and groups by are working fine, except the 3 based on user.id (ex. )
I get diffent js error, on different browsers:
Chrome & IE
Uncaught TypeError: Cannot read property 'length' of undefined
http://myserveraddress:8069/web/webclient/js?db=may_9:3256
Firefox:
TypeError: results.group_by is undefined
http://myserveraddress:8069/web/webclient/js?db=may_9:3256
I tryed to add context="{'group_by' : 'requestor'}", just in case, but I get the same error! Any ideia of what I'm missing here?
Thanks in advance.
I guess I'm loosing my mind with OpenERP. I was formatting badly the filter domain, I should use uid instead of user.id. This way, filters should be <filter icon="terp-mail-message-new" string="My Requests" name="my_requests_filter" domain="[('requestor','='uid)]" />
And, BTW, if one wants to set a filter as a default on tree view, it has to add the following code in the action definition:
<record model="ir.actions.act_window" id="action_generic_request">
<field name="name">Generic Request</field>
<field name="res_model">generic.request</field>
<field name="view_type">form</field>
<field name="context">{"search_default_my_requests_filter":1}</field>
<field name="view_mode">tree,form</field>
</record>
If my xml is structured like so:
<fruit>
<apple appleId="apple_1">
<core coreId="core_1">
<seed>1</seed>
<seed>2</seed>
</core>
</apple>
<apple appleId="apple_2">
<core coreId="core_1">
<seed>1</seed>
</core>
</apple>
</fruit>
and I want the seeds to be the documents in my solr schema, how can I access the appleId and coreId?
Here's the pertinent entity definition from my data-config.xml:
<entity name="apples"
processor="XPathEntityProcessor"
stream="true"
forEach="/fruit/apple/core/seed"
url="fruit.xml"
transformer="script:create_id"
>
<field column="seed_s" xpath="/fruit/apple/core/seed" />
<field column="apple_id_s" xpath="/fruit/apple/#appleId" />
</entity>
script:create_id creates a unique id for each seed.
In this example, apple_id_s is coming back as null.
I found the problem. I need to use commonField="true" and make sure to loop through each apple and core. Also, I need to set the pk="seed_s" which triggers solr to store the document.
Here's my new entity definition:
<entity name="apples"
processor="XPathEntityProcessor"
stream="true"
pk="seed_s"
forEach="/fruit/apple/core/seed | /fruit/apple | /fruit/apple/core"
url="fruit.xml"
transformer="script:create_id"
>
<field column="seed_s" xpath="/fruit/apple/core/seed" />
<field column="apple_id_s" xpath="/fruit/apple/#appleId" commonField="true"/>
<field column="core_id_s" xpath="/fruit/apple/core/#coreId" commonField="true"/>