diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2013-05-13 16:15:43 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2013-05-13 17:17:36 +0200 |
commit | 23c6b6ea166d670dfeaba4d4840bbd046f959a0d (patch) | |
tree | 040672981dd6593f41536c9172e7cec2941f83ea /sonar-plugin-api | |
parent | e2ae8af9e2a4817fcd7358ac22ec36ee607dc26a (diff) | |
download | sonarqube-23c6b6ea166d670dfeaba4d4840bbd046f959a0d.tar.gz sonarqube-23c6b6ea166d670dfeaba4d4840bbd046f959a0d.zip |
SONAR-4323 new web service /api/users/search
Diffstat (limited to 'sonar-plugin-api')
7 files changed, 305 insertions, 0 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQueryResult.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQueryResult.java index 612de445dfb..b40991195ff 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQueryResult.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQueryResult.java @@ -21,6 +21,7 @@ package org.sonar.api.issue; import org.sonar.api.component.Component; import org.sonar.api.rules.Rule; +import org.sonar.api.user.User; import org.sonar.api.utils.Paging; import javax.annotation.CheckForNull; @@ -35,10 +36,16 @@ public interface IssueQueryResult { Rule rule(Issue issue); + /** + * The rules involved in the paginated {@link #issues()}. + */ Collection<Rule> rules(); Component component(Issue issue); + /** + * The components involved in the paginated {@link #issues()}. + */ Collection<Component> components(); @CheckForNull @@ -46,6 +53,15 @@ public interface IssueQueryResult { Collection<ActionPlan> actionPlans(); + /** + * The users involved in the paginated {@link #issues()}, for example people who added a comment, created an issue + * or are assigned to issues. + */ + Collection<User> users(); + + @CheckForNull + User user(String login); + Paging paging(); boolean securityExclusions(); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/user/RubyUserService.java b/sonar-plugin-api/src/main/java/org/sonar/api/user/RubyUserService.java new file mode 100644 index 00000000000..5247f6b1efa --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/user/RubyUserService.java @@ -0,0 +1,42 @@ +/* + * 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. + */ +package org.sonar.api.user; + +import org.sonar.api.ServerComponent; + +import java.util.List; +import java.util.Map; + +/** + * @since 3.6 + */ +public interface RubyUserService extends ServerComponent { + + /** + * Search for users + * <p/> + * Optional parameters are: + * <ul> + * <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> + */ + List<User> find(Map<String, Object> params); +} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/user/User.java b/sonar-plugin-api/src/main/java/org/sonar/api/user/User.java new file mode 100644 index 00000000000..3a8c61d7833 --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/user/User.java @@ -0,0 +1,32 @@ +/* + * 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. + */ +package org.sonar.api.user; + +import java.io.Serializable; + +/** + * @since 3.6 + */ +public interface User extends Serializable { + String login(); + String name(); + String email(); + boolean active(); +} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/user/UserFinder.java b/sonar-plugin-api/src/main/java/org/sonar/api/user/UserFinder.java new file mode 100644 index 00000000000..66234bb177d --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/user/UserFinder.java @@ -0,0 +1,38 @@ +/* + * 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. + */ +package org.sonar.api.user; + +import org.sonar.api.ServerComponent; + +import javax.annotation.CheckForNull; +import java.util.List; + +/** + * @since 3.6 + */ +public interface UserFinder extends ServerComponent { + + @CheckForNull + User findByLogin(String login); + + List<User> findByLogins(List<String> logins); + + List<User> find(UserQuery query); +} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/user/UserQuery.java b/sonar-plugin-api/src/main/java/org/sonar/api/user/UserQuery.java new file mode 100644 index 00000000000..d4c84c728b4 --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/user/UserQuery.java @@ -0,0 +1,85 @@ +/* + * 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. + */ +package org.sonar.api.user; + +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; +import java.util.Arrays; +import java.util.Collection; + +/** + * @since 3.6 + */ +public class UserQuery { + + public static final UserQuery ALL_ACTIVES = UserQuery.builder().build(); + + private final Collection<String> logins; + private final boolean includeDeactivated; + + private UserQuery(Builder builder) { + this.logins = builder.logins; + this.includeDeactivated = builder.includeDeactivated; + } + + @CheckForNull + public Collection<String> logins() { + return logins; + } + + public boolean includeDeactivated() { + return includeDeactivated; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private boolean includeDeactivated = false; + private Collection<String> logins; + + private Builder() { + } + + public Builder includeDeactivated() { + this.includeDeactivated = true; + return this; + } + + public Builder logins(@Nullable Collection<String> logins) { + // TODO clone logins + this.logins = logins; + return this; + } + + public Builder logins(String... logins) { + this.logins = Arrays.asList(logins); + return this; + } + + public UserQuery build() { + if (logins != null && logins.size() >= 1000) { + throw new IllegalArgumentException("Max number of logins is 1000. Got " + logins.size()); + } + return new UserQuery(this); + } + } +} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/user/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/user/package-info.java new file mode 100644 index 00000000000..90afbfd128c --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/user/package-info.java @@ -0,0 +1,24 @@ +/* + * 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. + */ + +@ParametersAreNonnullByDefault +package org.sonar.api.user; + +import javax.annotation.ParametersAreNonnullByDefault;
\ No newline at end of file diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/user/UserQueryTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/user/UserQueryTest.java new file mode 100644 index 00000000000..e6dbc92a126 --- /dev/null +++ b/sonar-plugin-api/src/test/java/org/sonar/api/user/UserQueryTest.java @@ -0,0 +1,68 @@ +/* + * 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. + */ +package org.sonar.api.user; + +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import static org.fest.assertions.Assertions.assertThat; +import static org.fest.assertions.Fail.fail; + +public class UserQueryTest { + @Test + public void test_all_actives() throws Exception { + assertThat(UserQuery.ALL_ACTIVES.includeDeactivated()).isFalse(); + assertThat(UserQuery.ALL_ACTIVES.logins()).isNull(); + } + + @Test + public void test_all() throws Exception { + UserQuery all = UserQuery.builder().includeDeactivated().build(); + assertThat(all.includeDeactivated()).isTrue(); + assertThat(all.logins()).isNull(); + } + + @Test + public void test_logins() throws Exception { + UserQuery query = UserQuery.builder().logins("simon", "loic").build(); + assertThat(query.includeDeactivated()).isFalse(); + assertThat(query.logins()).containsOnly("simon", "loic"); + + query = UserQuery.builder().logins(Arrays.asList("simon", "loic")).build(); + assertThat(query.logins()).containsOnly("simon", "loic"); + } + + @Test + public void should_limit_number_of_logins() throws Exception { + List<String> logins = new ArrayList<String>(); + for (int i = 0; i < 1010; i++) { + logins.add(String.valueOf(i)); + } + try { + UserQuery.builder().logins(logins).build(); + fail(); + } catch (IllegalArgumentException e) { + assertThat(e).hasMessage("Max number of logins is 1000. Got 1010"); + } + } +} |