<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How is the  multi tenant user query supposed to work? in Nuxeo Forum</title>
    <link>https://connect.hyland.com/t5/nuxeo-forum/how-is-the-multi-tenant-user-query-supposed-to-work/m-p/323368#M10369</link>
    <description>&lt;P&gt;I'm using the Automation API to create users for isolated tenants with the multi-tenant plugin installed.&lt;/P&gt;
&lt;P&gt;Before creating the user I check if they already exist by querying using something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;        Blob blob = (Blob) session.newRequest("Services.QueryUsers")
                .set("pattern", userId)
                .set("tenantId", tenantId)
                .execute();
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Sadly, however, even if I have a user with that userId in that tenant I get back 0 users.&lt;/P&gt;
&lt;P&gt;I believe that this is because of the code in &lt;CODE&gt;QueryUsers&lt;/CODE&gt; which is part of the multi-tenant plugin. As
part of the &lt;CODE&gt;run()&lt;/CODE&gt; method there is code which does this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;        Map&amp;lt;String, Serializable&amp;gt; filter = new HashMap&amp;lt;String, Serializable&amp;gt;();
        for (String field : FULLTEXT_FIELDS) {
            filter.put(field, pattern);

            if (!StringUtils.isBlank(tenantId)) {
                filter.put("tenantId", tenantId);
            }

            users.addAll(userManager.searchUsers(filter, filter.keySet()));
        }
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;however I believe that the creation of the filter should be moved inside the loop like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;         for (String field : FULLTEXT_FIELDS) {
             Map&amp;lt;String, Serializable&amp;gt; filter = new HashMap&amp;lt;String, Serializable&amp;gt;();
            filter.put(field, pattern);

            if (!StringUtils.isBlank(tenantId)) {
                filter.put("tenantId", tenantId);
            }

            users.addAll(userManager.searchUsers(filter, filter.keySet()));
        }
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which will give you a match for a userId, lastname or firstName. Currently even though I use an existing userId I get nothing back as the &lt;CODE&gt;Set&lt;/CODE&gt; used for &lt;CODE&gt;FULLTEXT_FIELDS&lt;/CODE&gt; supplies lastname first and I am never matching that.&lt;/P&gt;
&lt;P&gt;I've patched my version and it seems to work fine - What is the protocol for pull requests etc?&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Thu, 22 Jan 2015 07:42:58 GMT</pubDate>
    <dc:creator>John_Murray</dc:creator>
    <dc:date>2015-01-22T07:42:58Z</dc:date>
    <item>
      <title>How is the  multi tenant user query supposed to work?</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/how-is-the-multi-tenant-user-query-supposed-to-work/m-p/323368#M10369</link>
      <description>&lt;P&gt;I'm using the Automation API to create users for isolated tenants with the multi-tenant plugin installed.&lt;/P&gt;
&lt;P&gt;Before creating the user I check if they already exist by querying using something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;        Blob blob = (Blob) session.newRequest("Services.QueryUsers")
                .set("pattern", userId)
                .set("tenantId", tenantId)
                .execute();
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Sadly, however, even if I have a user with that userId in that tenant I get back 0 users.&lt;/P&gt;
&lt;P&gt;I believe that this is because of the code in &lt;CODE&gt;QueryUsers&lt;/CODE&gt; which is part of the multi-tenant plugin. As
part of the &lt;CODE&gt;run()&lt;/CODE&gt; method there is code which does this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;        Map&amp;lt;String, Serializable&amp;gt; filter = new HashMap&amp;lt;String, Serializable&amp;gt;();
        for (String field : FULLTEXT_FIELDS) {
            filter.put(field, pattern);

            if (!StringUtils.isBlank(tenantId)) {
                filter.put("tenantId", tenantId);
            }

            users.addAll(userManager.searchUsers(filter, filter.keySet()));
        }
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;however I believe that the creation of the filter should be moved inside the loop like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;         for (String field : FULLTEXT_FIELDS) {
             Map&amp;lt;String, Serializable&amp;gt; filter = new HashMap&amp;lt;String, Serializable&amp;gt;();
            filter.put(field, pattern);

            if (!StringUtils.isBlank(tenantId)) {
                filter.put("tenantId", tenantId);
            }

            users.addAll(userManager.searchUsers(filter, filter.keySet()));
        }
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which will give you a match for a userId, lastname or firstName. Currently even though I use an existing userId I get nothing back as the &lt;CODE&gt;Set&lt;/CODE&gt; used for &lt;CODE&gt;FULLTEXT_FIELDS&lt;/CODE&gt; supplies lastname first and I am never matching that.&lt;/P&gt;
&lt;P&gt;I've patched my version and it seems to work fine - What is the protocol for pull requests etc?&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jan 2015 07:42:58 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/how-is-the-multi-tenant-user-query-supposed-to-work/m-p/323368#M10369</guid>
      <dc:creator>John_Murray</dc:creator>
      <dc:date>2015-01-22T07:42:58Z</dc:date>
    </item>
    <item>
      <title>Re: How is the  multi tenant user query supposed to work?</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/how-is-the-multi-tenant-user-query-supposed-to-work/m-p/323369#M10370</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Thanks for the report.
I've created a JIRA issue for it: &lt;A href="https://jira.nuxeo.com/browse/NXP-16448"&gt;NXP-16448&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;I will fix it according to your solution.
It will be available on the next FT 7.2, and I will backport it on 6.0 also.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jan 2015 14:48:02 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/how-is-the-multi-tenant-user-query-supposed-to-work/m-p/323369#M10370</guid>
      <dc:creator>Thomas_Roger</dc:creator>
      <dc:date>2015-01-29T14:48:02Z</dc:date>
    </item>
  </channel>
</rss>

