<if test="includeDeactivated==false">
and u.active=${_true}
</if>
+ <if test="searchText != null">
+ and (u.login like #{searchTextSql} or u.name like #{searchTextSql})
+ </if>
</where>
order by u.name
</select>
assertThat(users.get(0).getName()).isEqualTo("Marius");
}
+ @Test
+ public void selectUsersByQuery_search_by_login_text() throws Exception {
+ setupData("selectUsersByText");
+
+ UserQuery query = UserQuery.builder().searchText("sbr").build();
+ List<UserDto> users = dao.selectUsers(query);
+ assertThat(users).hasSize(1);
+ assertThat(users.get(0).getLogin()).isEqualTo("sbrandhof");
+ }
+
+ @Test
+ public void selectUsersByQuery_search_by_name_text() throws Exception {
+ setupData("selectUsersByText");
+
+ UserQuery query = UserQuery.builder().searchText("Simon").build();
+ List<UserDto> users = dao.selectUsers(query);
+ assertThat(users).hasSize(1);
+ assertThat(users.get(0).getLogin()).isEqualTo("sbrandhof");
+ }
+
@Test
public void selectGroupByName() {
setupData("selectGroupByName");
--- /dev/null
+<!--
+ ~ SonarQube, open source software quality management tool.
+ ~ Copyright (C) 2008-2013 SonarSource
+ ~ mailto:contact AT sonarsource DOT com
+ ~
+ ~ SonarQube is free software; you can redistribute it and/or
+ ~ modify it under the terms of the GNU Lesser General Public
+ ~ License as published by the Free Software Foundation; either
+ ~ version 3 of the License, or (at your option) any later version.
+ ~
+ ~ SonarQube is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ ~ Lesser General Public License for more details.
+ ~
+ ~ You should have received a copy of the GNU Lesser General Public License
+ ~ along with this program; if not, write to the Free Software Foundation,
+ ~ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ -->
+<dataset>
+ <users id="101" login="marius" name="Marius" email="marius@lesbronzes.fr" created_at="2011-05-18" updated_at="2012-07-21" active="[true]"/>
+ <users id="102" login="sbrandhof" name="Simon Brandhof" email="marius@lesbronzes.fr" created_at="2011-05-18" updated_at="2012-07-21" active="[true]"/>
+
+</dataset>
*/
public interface RubyIssueService extends ServerComponent {
+ IssueQueryResult find(String issueKey);
+
/**
* Search for issues.
* <p/>
* <p/>
* Optional parameters are:
* <ul>
+ * <li><code>q</code> to match all the logins or names containing this search query</li>
* <li><code>logins</code>, as an array of strings (['simon', 'julien']) or a comma-separated list of logins ('simon,julien')</li>
* <li><code>includeDeactivated</code> as a boolean. By Default deactivated users are excluded from query.</li>
* </ul>
*/
package org.sonar.api.user;
+import org.apache.commons.lang.StringUtils;
+
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import java.util.Arrays;
private final Collection<String> logins;
private final boolean includeDeactivated;
+ private final String searchText;
+
+ // for internal use in MyBatis
+ final String searchTextSql;
private UserQuery(Builder builder) {
this.logins = builder.logins;
this.includeDeactivated = builder.includeDeactivated;
+ this.searchText = builder.searchText;
+ this.searchTextSql = (searchText !=null ? "%" + searchText + "%" : null);
}
@CheckForNull
return includeDeactivated;
}
+ /**
+ * Search for logins or names containing a given string
+ */
+ @CheckForNull
+ public String searchText() {
+ return searchText;
+ }
+
public static Builder builder() {
return new Builder();
}
public static class Builder {
private boolean includeDeactivated = false;
private Collection<String> logins;
+ private String searchText;
private Builder() {
}
return this;
}
+ public Builder searchText(@Nullable String s) {
+ this.searchText = StringUtils.defaultIfBlank(s, null);
+ return this;
+ }
+
public UserQuery build() {
if (logins != null && logins.size() >= 1000) {
throw new IllegalArgumentException("Max number of logins is 1000. Got " + logins.size());
public void test_all_actives() throws Exception {
assertThat(UserQuery.ALL_ACTIVES.includeDeactivated()).isFalse();
assertThat(UserQuery.ALL_ACTIVES.logins()).isNull();
+ assertThat(UserQuery.ALL_ACTIVES.searchText()).isNull();
+ assertThat(UserQuery.ALL_ACTIVES.searchTextSql).isNull();
}
@Test
assertThat(e).hasMessage("Max number of logins is 1000. Got 1010");
}
}
+
+ @Test
+ public void test_searchText() throws Exception {
+ UserQuery query = UserQuery.builder().searchText("sim").build();
+ assertThat(query.searchText()).isEqualTo("sim");
+ assertThat(query.searchTextSql).isEqualTo("%sim%");
+ }
}
builder.includeDeactivated();
}
builder.logins(RubyUtils.toStrings(params.get("logins")));
+ builder.searchText((String)params.get("q"));
return builder.build();
}
}
#
def search
users = Api.users.find(params)
- hash = {
- :users => users.map { |user| User.to_hash(user) }
- }
+
+ select2_format=(params[:f]=='s2')
+ if select2_format
+ hash = {
+ :more => false,
+ :results => users.map { |user| {:id => user.login, :text => "#{user.name} (#{user.login})"} }
+ }
+ else
+ hash = {:users => users.map { |user| User.to_hash(user) }}
+ end
+
respond_to do |format|
format.json { render :json => jsonp(hash) }
import org.sonar.wsclient.internal.EncodingUtils;
+import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.Map;
return this;
}
+ public UserQuery searchText(@Nullable String s) {
+ if (s != null) {
+ params.put("q", s);
+ } else {
+ params.remove("q");
+ }
+ return this;
+ }
+
Map<String, Object> urlParams() {
return params;
}
UserQuery query = UserQuery.create().logins("simon").logins("loic");
assertThat(query.urlParams().get("logins")).isEqualTo("loic");
}
+
+ @Test
+ public void should_search_by_text() throws Exception {
+ UserQuery query = UserQuery.create().searchText("sim");
+ assertThat(query.urlParams().get("q")).isEqualTo("sim");
+ }
}