[xwiki-users] REST query to fetch filtered list of users and some of their attributes
In our Xwiki, I've added some fields such as birthday (of type Date) to the user profile. I'd like to implement a REST call that retrieves all of the non-hidden users with birthdays in a specific month (typically the current month) and some specific attribute values. Right now the values I want are the first name, last name, birthday and the link to the avatar image file. I have bits and pieces of the solution but am having trouble with some parts - specifically how to put it together into a single REST call. PROBLEM 1: I can create a page with a script like the following to filter some users and display their names. {{velocity}} #set ($tags=$services.query.xwql("select obj.first_name from Document doc, doc.object(XWiki.XWikiUsers) as obj where (obj.first_name LIKE '%a%' and (doc.hidden <> true OR doc.hidden is null))").execute()) $tags {{/velocity}} But if I try to execute that query in a REST call like the following, the result is different .../rest/wikis/query?q=select+obj.first_name+from+Document+doc%2C+doc.object%28XWiki.XWikiUsers%29+as+obj+where+%28obj.first_name+LIKE+%27%25a%25%27+and+%28doc.hidden+%3C%3E+true+OR+doc.hidden+is+null%29%29&type=xwql The REST call returns some data completely unrelated to the users: <searchResults template="http://...rest?q={solrquery}(&number={number})(&start={start})(&orderField={fieldname}(&order={asc|desc}))(&distinct=1)(&prettyNames={false|true})(&wikis={wikis})(&className={classname})"><searchResult><link href="http://...rest/wikis/xwiki/spaces/XWiki/pages/DocumentTreeMacros" rel="http://www.xwiki.org/rel/page"/><type>page</type><id>xwiki:XWiki.DocumentTreeMacros</id><pageFullName>XWiki.DocumentTreeMacros</pageFullName><wiki>xwiki</wiki><space>XWiki</space><pageName>DocumentTreeMacros</pageName><modified>2016-02-15T12:14:34-03:00</modified><author>xwiki:XWiki.Admin</author><version>4.1</version><score>0.62450576</score></searchResult><searchResult><link href="http://...rest/wikis/xwiki/spaces/XWiki/pages/DocumentTree" rel="http://www.xwiki.org/rel/page"/><type>page</type><id>xwiki:XWiki.DocumentTree</id><pageFullName>XWiki.DocumentTree</pageFullName><wiki>xwiki</wiki><space>XWiki</space><pageName>DocumentTree</pageName><modified>2016-01-27T10:23:05-03:00</modified><author>xwiki:XWiki.Admin</author><version>2.1</version><score>0.5804536</score></searchResult><searchResult><link href="http://...rest/wikis/xwiki/spaces/Panels/pages/DocumentInformation" rel="http://www.xwiki.org/rel/page"/><type>page</type><id>xwiki:Panels.DocumentInformation</id><pageFullName>Panels.DocumentInformation</pageFullName><wiki>xwiki</wiki><space>Panels</space><pageName>DocumentInformation</pageName><modified>2016-01-12T09:56:52-03:00</modified><author>xwiki:XWiki.superadmin</author><version>1.1</version><score>0.4841085</score></searchResult> PROBLEM 2: If I try to implement a query that retrieves multiple fields from the user profile like the following: {{velocity}} #set ($tags=$services.query.xwql("select obj.first_name, obj.last_name, obj.birthday from Document doc, doc.object(XWiki.XWikiUsers) as obj where (obj.first_name LIKE '%a%' and (doc.hidden <> true OR doc.hidden is null))").execute()) $tags {{/velocity}} the data displayed in the xwiki page looks like the following instead the actual attribute values: [[Ljava.lang.Object;@723f4d95, [Ljava.lang.Object;@4054e1bb, [Ljava.lang.Object;@436c8d04, [Ljava.lang.Object;@5c93ddc1, [Ljava.lang.Object;@54c86023, [Ljava.lang.Object;@33760a38, [Ljava.lang.Object;@14d5b5ff, [Ljava.lang.Object;@566a1f71, [Ljava.lang.Object;@41b4b4e7, [Ljava.lang.Object;@42904123, [Ljava.lang.Object;@7b536ec3, [Ljava.lang.Object;@7d44674f, [Ljava.lang.Object;@1933e78c, [Ljava.lang.Object;@59ea34d0, [Ljava.lang.Object;@392f7c58, [Ljava.lang.Object;@678f1a2d, [Ljava.lang.Object;@61868ed7, [Ljava.lang.Object;@69426a83, [Ljava.lang.Object;@2bcd164f, [Ljava.lang.Object;@340c3f69, [Ljava.lang.Object;@6129ef09, [Ljava.lang.Object;@1b4587dd, [Ljava.lang.Object;@58799594, [Ljava.lang.Object;@d5b1e85, [Ljava.lang.Object;@2324f980, [Ljava.lang.Object;@1468f956, [Ljava.lang.Object;@290b7a] Regards Mark Sack -- View this message in context: http://xwiki.475771.n2.nabble.com/REST-query-to-fetch-filtered-list-of-users... Sent from the XWiki- Users mailing list archive at Nabble.com.
Hi Mark,
On 20 May 2016, at 16:45, Mark Sack <[email protected]> wrote:
In our Xwiki, I've added some fields such as birthday (of type Date) to the user profile. I'd like to implement a REST call that retrieves all of the non-hidden users with birthdays in a specific month (typically the current month) and some specific attribute values. Right now the values I want are the first name, last name, birthday and the link to the avatar image file. I have bits and pieces of the solution but am having trouble with some parts - specifically how to put it together into a single REST call.
PROBLEM 1: I can create a page with a script like the following to filter some users and display their names. {{velocity}} #set ($tags=$services.query.xwql("select obj.first_name from Document doc, doc.object(XWiki.XWikiUsers) as obj where (obj.first_name LIKE '%a%' and (doc.hidden <> true OR doc.hidden is null))").execute()) $tags {{/velocity}}
But if I try to execute that query in a REST call like the following, the result is different .../rest/wikis/query?q=select+obj.first_name+from+Document+doc%2C+doc.object%28XWiki.XWikiUsers%29+as+obj+where+%28obj.first_name+LIKE+%27%25a%25%27+and+%28doc.hidden+%3C%3E+true+OR+doc.hidden+is+null%29%29&type=xwql
The REST call returns some data completely unrelated to the users: <searchResults template="http://...rest?q={solrquery}(&number={number})(&start={start})(&orderField={fieldname}(&order={asc|desc}))(&distinct=1)(&prettyNames={false|true})(&wikis={wikis})(&className={classname})"><searchResult><link href="http://...rest/wikis/xwiki/spaces/XWiki/pages/DocumentTreeMacros" rel="http://www.xwiki.org/rel/page"/><type>page</type><id>xwiki:XWiki.DocumentTreeMacros</id><pageFullName>XWiki.DocumentTreeMacros</pageFullName><wiki>xwiki</wiki><space>XWiki</space><pageName>DocumentTreeMacros</pageName><modified>2016-02-15T12:14:34-03:00</modified><author>xwiki:XWiki.Admin</author><version>4.1</version><score>0.62450576</score></searchResult><searchResult><link href="http://...rest/wikis/xwiki/spaces/XWiki/pages/DocumentTree" rel="http://www.xwiki.org/rel/page"/><type>page</type><id>xwiki:XWiki.DocumentTree</id><pageFullName>XWiki.DocumentTree</pageFullName><wiki>xwiki</wiki><space>XWiki</space><pageName>DocumentTree</pageName><modified>2016-01-27T10:23:05-03:00</modified><author>xwiki:XWiki.Admin</author><version>2.1</version><score>0.5804536</score></searchResult><searchResult><link href="http://...rest/wikis/xwiki/spaces/Panels/pages/DocumentInformation" rel="http://www.xwiki.org/rel/page"/><type>page</type><id>xwiki:Panels.DocumentInformation</id><pageFullName>Panels.DocumentInformation</pageFullName><wiki>xwiki</wiki><space>Panels</space><pageName>DocumentInformation</pageName><modified>2016-01-12T09:56:52-03:00</modified><author>xwiki:XWiki.superadmin</author><version>1.1</version><score>0.4841085</score></searchResult>
PROBLEM 2: If I try to implement a query that retrieves multiple fields from the user profile like the following: {{velocity}} #set ($tags=$services.query.xwql("select obj.first_name, obj.last_name, obj.birthday from Document doc, doc.object(XWiki.XWikiUsers) as obj where (obj.first_name LIKE '%a%' and (doc.hidden <> true OR doc.hidden is null))").execute()) $tags {{/velocity}}
the data displayed in the xwiki page looks like the following instead the actual attribute values:
[[Ljava.lang.Object;@723f4d95, [Ljava.lang.Object;@4054e1bb, [Ljava.lang.Object;@436c8d04, [Ljava.lang.Object;@5c93ddc1, [Ljava.lang.Object;@54c86023, [Ljava.lang.Object;@33760a38, [Ljava.lang.Object;@14d5b5ff, [Ljava.lang.Object;@566a1f71, [Ljava.lang.Object;@41b4b4e7, [Ljava.lang.Object;@42904123, [Ljava.lang.Object;@7b536ec3, [Ljava.lang.Object;@7d44674f, [Ljava.lang.Object;@1933e78c, [Ljava.lang.Object;@59ea34d0, [Ljava.lang.Object;@392f7c58, [Ljava.lang.Object;@678f1a2d, [Ljava.lang.Object;@61868ed7, [Ljava.lang.Object;@69426a83, [Ljava.lang.Object;@2bcd164f, [Ljava.lang.Object;@340c3f69, [Ljava.lang.Object;@6129ef09, [Ljava.lang.Object;@1b4587dd, [Ljava.lang.Object;@58799594, [Ljava.lang.Object;@d5b1e85, [Ljava.lang.Object;@2324f980, [Ljava.lang.Object;@1468f956, [Ljava.lang.Object;@290b7a]
You get a list Object[] each Object corresponding to a column of your select. For ex Object[0] is the “obj.first_name”, etc. Thanks -Vincent
Regards Mark Sack
View this message in context: http://xwiki.475771.n2.nabble.com/REST-query-to-fetch-filtered-list-of-users... Sent from the XWiki- Users mailing list archive at Nabble.com.
OK. I understand how to display the attributes on the web page with some more velocity commands (i.e. a couple of for loops). But I'm still stuck on how to translate that into a single REST call (in addition to the first problem of the erroneous (perhaps my error) results in the REST call. Thanks for the quick response. Mark -- View this message in context: http://xwiki.475771.n2.nabble.com/REST-query-to-fetch-filtered-list-of-users... Sent from the XWiki- Users mailing list archive at Nabble.com.
participants (2)
-
Mark Sack -
Vincent Massol