I have an XML like this.
<?xml version="1.0" encoding="UTF-8"?>
<doc>
<ticker> CSGN.VX </ticker>
<stockExchange> NYSE </stockExchange>
<stockDatas>
<stockData>
<date>2015-08-06</date>
<closingPrice>140</closingPrice>
</stockData>
<stockData>
<date>2015-08-07</date>
<closingPrice>140.25</closingPrice>
</stockData>
<stockData>
<date>2015-08-10</date>
<closingPrice>140.75</closingPrice>
</stockData>
</stockDatas>
</doc>
And I will be having similar XMLs for different companies around different years. Now I want to search for documents which have the ticker as CSGN.VX for a particular time duration, so I use this query.
xquery version "1.0-ml";
import module namespace search = "http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy";
search:search(
'ticker:CSGN.VX AND (dateRange GE "2015-08-07" AND dateRange LE "2015-08-21")',
<options xmlns="http://marklogic.com/appservices/search">
<constraint name="dateRange">
<range type="xs:date" facet="false">
<element ns="" name="date"/>
</range>
</constraint>
<constraint name="ticker">
<range type="xs:string" >
<element ns="" name="ticker"/>
</range>
</constraint>
</options>)
Is there a way where along with the document search, I can also get the closingPrice average for that particular time duration?
I just got a solution but i have a further query, i was looking for a way to implement this using java client API of Marklogic so is there a way to implement search:parse and search:values using Java Client API
I know one way to implement this is through MarklogicXCC API but i wanted to know if there is a way through which these functions can be run using Client API
Provided you have a range index on closingPrice you should be able to do something like this:
xquery version "1.0-ml";
import module namespace search = "http://marklogic.com/appservices/search"at "/MarkLogic/appservices/search/search.xqy";
let $query :=
search:parse(
'ticker:CSGN.VX AND (dateRange GE "2015-08-07" AND dateRange LE "2015-08-21")',
<options xmlns="http://marklogic.com/appservices/search">
<constraint name="dateRange">
<range type="xs:date" facet="false">
<element ns="" name="date"/>
</range>
</constraint>
<constraint name="ticker">
<range type="xs:string" >
<element ns="" name="ticker"/>
</range>
</constraint>
</options>,
"search:query"
)
return
search:values(
'closingPrice',
<options xmlns="http://marklogic.com/appservices/search">
<values name="closingPrice">
<range type="xs:double">
<element ns="" name="closingPrice"/>
</range>
<aggregate apply="avg"/>
</values>
</options>,
$query
)
Note: I do recommend storing each stockData separately, otherwise the dateRange filter probably won't work as expected.
HTH!
Related
I would like to turn this xml response into something more easily readable.
<?xml version="1.0" encoding="ISO-8859-1"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"/>
<soap:Body>
<executeResponse xmlns="urn:GCE">
<BusinessViewServiceexecuteOut xmlns="http://www.generix.fr/technicalframework/businesscomponent/applicationmodule/common" xmlns:ns2="http://www.generixgroup.com/processus/configuration/scheduler" xmlns:ns3="http://www.generix.fr/technicalframework/business/service/common">
<xmlpres><?xml version = '1.0' encoding = 'UTF-8'?> <VueTable type="View" name="Table" habctr="true" total_business_row="2" nbline="400" confNbline="400" numpage="1" nbpage="1">
<JTblView name="JTblView" type="ViewObject" maxfetchsize="999" maxfetchsizeexceeded="false">
<JTblViewRow current="true" type="ViewRow" index="1" business_row_index="1">
<Cletbl precision="6" type="VARCHAR" pk="true">
<business_data>N</business_data>
</Cletbl>
<Codtbl precision="6" type="VARCHAR" pk="true">
<business_data>001</business_data>
</Codtbl>
<Lib1 precision="30" type="VARCHAR">
<business_data>Non</business_data>
</Lib1>
<Lib2 precision="30" type="VARCHAR">
<business_data/>
</Lib2>
<Lir precision="10" type="VARCHAR">
<business_data>Non</business_data>
</Lir>
</JTblViewRow>
<JTblViewRow type="ViewRow" index="2" business_row_index="2">
<Cletbl precision="6" type="VARCHAR" pk="true">
<business_data>O</business_data>
</Cletbl>
<Codtbl precision="6" type="VARCHAR" pk="true">
<business_data>001</business_data>
</Codtbl>
<Lib1 precision="30" type="VARCHAR">
<business_data>Oui</business_data>
</Lib1>
<Lib2 precision="30" type="VARCHAR">
<business_data/>
</Lib2>
<Lir precision="10" type="VARCHAR">
<business_data>Oui</business_data>
</Lir>
</JTblViewRow>
</JTblView>
</VueTable></xmlpres>
</BusinessViewServiceexecuteOut>
</executeResponse>
</soap:Body></soap:Envelope>
At least if I could extract what's in the value of "xmlpres", the better I could do:
<table><row><code></code><libelle></libelle/></row></table>
To then turn it into a json response but I can't see ... I just get all the output or in json stream but with everything , which is not usable.
Create an out-mediation sequence with the following content and attach it to the respective API and try out the scenario. This is to extract the xmlpres content and send that as the response to the client
<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="out-sequence">
<!-- extract the xmlpres content and store as OM element -->
<property name="XMLBody"
expression="$body//soap:Body//generic:xmlpres"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:gce="urn:GCE"
xmlns:generic="http://www.generix.fr/technicalframework/businesscomponent/applicationmodule/common" type="OM" />
<!-- pass the extracted property as response body -->
<enrich>
<source type="property" property="XMLBody" />
<target type="body" />
</enrich>
</sequence>
Hope this helps you to extract and send the response accordingly.
I have this canonical structure:
<xsd:complexType name="Document">
<xsd:attribute name="ID" use="optional" type="cdpscm:IDDocument"/>
</xsd:complexType>
<xsd:element name="NationalID" type="cdpscm:NationalID"/>
<xsd:complexType name="NationalID">
<xsd:complexContent>
<xsd:extension base="cdpscm:Document">
<xsd:sequence>
<xsd:element name="Number"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="Passaport" type="cdpscm:Passaport"/>
<xsd:complexType name="Passaport">
<xsd:complexContent>
<xsd:extension base="cdpscm:Document">
<xsd:sequence>
<xsd:element name="Number"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
Who calls my OSB service will cast if the document is a Passaport or a NationalID, but how I get the number value to pass to another service, for example, if I only have the Document element type which doesn't has the number element.
This is the supossed input:
<v24:Person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="v2:TouristPerson" ID="5772893">
<v2:Documents>
<v2:Document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="v2:Passport">
<v2:Number>03070</v2:Number>
</v2:Document>
</v2:Documents>
</v24:Person>
The real structure is more complex than this, so probably will need to know if I'm working with NationalID or Passaport, a Tourist or a Native Person.
Using Oracle 11g, Eclipse OEPE.
Thanks for the help!
Something like this should work.
declare namespace xsi = "http://www.w3.org/2001/XMLSchema-instance";
let $documents := $body//v24:Person/v2:Documents/v2:Document
for $passport in $documents[#xsi:type="v2:Passport"]
return data($passport/v2:Number)
(: similarly for national IDs :)
I got the following part of code from Odoo community reference website for creating birthday calendar mark ups
.PY file
class birthday_report(osv.osv):
_name = "birthday.report"
_auto = False
_columns = {
'name': fields.many2one('hr.employee','Employee', readonly=True),
'dob' : fields.date('Birthday', readonly=True),
}
def init(self, cr):
tools.drop_view_if_exists(cr, 'birthday_report')
cr.execute("""
create or replace view birthday_report as (
select
h.id as id,
h.id as name,
concat(concat(date_part('Year',current_date),'-'),to_char(h.birthday, 'mm-dd')) as dob
from
hr_employee as h
join
resource_resource as r
on
h.resource_id=r.id
where r.active ='t'
)
""")
birthday_report()
.XML file
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_birthday_report_calendar" model="ir.ui.view">
<field name="name">Employee Birthday</field>
<field name="model">birthday.report</field>
<field name="arch" type="xml">
<calendar string="Birthday" color="name"
date_start="dob"
quick_add="False" avatar_model="hr.employee">
<field name="name"/>
</calendar>
</field>
</record>
<record model="ir.actions.act_window" id="action_birthday_view">
<field name="name">Birthday</field>
<field name="res_model">birthday.report</field>
<field name="view_type">form</field>
<field name="view_mode">calendar</field>
<field name="view_id" eval="view_birthday_report_calendar"/>
<field name="domain">[]</field>
</record>
<menuitem id="menu_birthday" name="Birthday" parent="hr.menu_hr_root" groups="base.group_user"/>
<menuitem id="menu_view_birthday" parent="menu_birthday" action="action_birthday_view" groups="base.group_user"/>
</data>
</openerp>
Error shows up when I navigate to January or previous year December, the following error occurs :
Uncaught Error: '2016-' is not a correct date, datetime nor time.
I am new to sql queries in Odoo, Anyone with suggestions on this would be really grateful. Thanks !!
First, I recommend using || instead of concat. That allows you to do multiple concatenations.
date_part('Year',current_date) || '-' || to_char(h.birthday, 'mm-dd')
Secondly I recommend casting to date, so
(date_part('Year',current_date) || '-' || to_char(h.birthday, 'mm-dd'))::date
Third, what happens if you just use psql and select from the view? Are there malformed dates? Or is something else happening elsewhere in your Python code?
I want to sort results on the basis of facet count. How can I go that in search:search?
As of now, I am using this query -
let $options :=
<options xmlns="http://marklogic.com/appservices/search">
<return-metrics>false</return-metrics>
<return-facets>true</return-facets>
<return-results>false</return-results>
<additional-query>{cts:query($cts-query)}</additional-query>
<constraint name="decade">
<range type="xs:dateTime" facet="true">
<bucket lt="2002-01-01T00:00:00Z" ge="2001-01-01T00:00:00Z" name="2001">2001</bucket>
<bucket lt="2003-01-01T00:00:00Z" ge="2002-01-01T00:00:00Z" name="2002">2002</bucket>
<bucket lt="2004-01-01T00:00:00Z" ge="2003-01-01T00:00:00Z" name="2003">2003</bucket>
<bucket ge="2004-01-01T00:00:00Z" name="2004">2004</bucket>
<facet-option>limit=10</facet-option>
<element ns="http://iddn.icis.com/ns/core" name="released-on"/>
</range>
</constraint>
<operator>
<state>
<sort-order direction="descending" type="xs:integer">
<score/>
</sort-order>
</state>
</operator>
</options>
let $date-seq := search:search("*", $options)
return $date-seq
I want to change the options so that I can sort the facet results by facet count.
Haven't tried this with buckets, but normally I think you'd add facet-options "frequency-order" and "descending":
<constraint name="decade">
<range type="xs:dateTime" facet="true">
<bucket lt="2002-01-01T00:00:00Z" ge="2001-01-01T00:00:00Z" name="2001">2001</bucket>
<bucket lt="2003-01-01T00:00:00Z" ge="2002-01-01T00:00:00Z" name="2002">2002</bucket>
<bucket lt="2004-01-01T00:00:00Z" ge="2003-01-01T00:00:00Z" name="2003">2003</bucket>
<bucket ge="2004-01-01T00:00:00Z" name="2004">2004</bucket>
<facet-option>limit=10</facet-option>
<facet-option>frequency-order</facet-option>
<facet-option>descending</facet-option>
<element ns="http://iddn.icis.com/ns/core" name="released-on"/>
</range>
</constraint>
The modified model_source of a dexterity type is not available for other clients until the other client restarts.
Invalidating or clearing the SCHEMA_CACHE is not a working solution: every client seems to have its own SCHEMA_CACHE which afik cannot be cleared or invalidated from another client.
Is there any solution to solve this problem?
The scenario presented here uses ipython as second client. The same can be reproduced through the web by starting two clients: (1) create a dexterity type in client1, and (2) edit the XML Field Model in client2.
I'd like to put this as an issue on https://github.com/plone/plone.dexterity but as for today issues seem not to be available in the plone.dexterity github project
utils.sync()
from Products.CMFCore.utils import getToolByName
from plone.dexterity.fti import DexterityFTI
id = 'mydexteritytype'
plone_site = app.Plone
tool_portal_types = getToolByName(plone_site, 'portal_types')
if tool_portal_types.hasObject(id): tool_portal_types.manage_delObjects(id)
utils.commit()
utils.sync()
fti = DexterityFTI(id)
fti.id = id
data = {}
data['title'] = id
data['i18n_domain'] = 'plone'
data['behaviors'] = "\n".join([
'plone.app.dexterity.behaviors.metadata.IDublinCore',
'plone.app.content.interfaces.INameFromTitle',
])
data['model_source'] = '''
<model xmlns:security="http://namespaces.plone.org/supermodel/security"
xmlns:marshal="http://namespaces.plone.org/supermodel/marshal"
xmlns:form="http://namespaces.plone.org/supermodel/form"
xmlns="http://namespaces.plone.org/supermodel/schema">
<schema>
<field name="original" type="zope.schema.TextLine">
<default>original</default>
<description/>
<title>original</title>
</field>
</schema>
</model>'''
data['klass'] = 'plone.dexterity.content.Container'
data['filter_content_types'] = True
data['icon_expr'] = 'string:${portal_url}/document_icon.png'
fti.manage_changeProperties(**data)
tool_portal_types._setObject(fti.id, fti)
utils.commit()
After running the code above, the new created mydexteritytype is available for all other clients.
The modifications produced by the following code will be only available in the client running the code. All other clients are not aware of the changes.
utils.sync()
from plone.dexterity.interfaces import IDexterityFTI
from zope.component import getUtility
fti = getUtility(IDexterityFTI, name=id)
model_source = '''
<model xmlns:security="http://namespaces.plone.org/supermodel/security"
xmlns:marshal="http://namespaces.plone.org/supermodel/marshal"
xmlns:form="http://namespaces.plone.org/supermodel/form"
xmlns="http://namespaces.plone.org/supermodel/schema">
<schema>
<field name="modified" type="zope.schema.TextLine">
<default>modified</default>
<description/>
<title>modified</title>
</field>
</schema>
</model>'''
fti.manage_changeProperties(model_source=model_source)
from plone.dexterity.schema import SCHEMA_CACHE
SCHEMA_CACHE.invalidate(fti)
SCHEMA_CACHE.clear()
utils.commit()
This pull-request is supposed to fix this issue:
https://github.com/plone/plone.dexterity/pull/137