aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2013-04-10 17:58:43 +0200
committerJulien Lancelot <julien.lancelot@gmail.com>2013-04-10 17:58:43 +0200
commite1d9aa49cb8f8fff3b17d884e008f6ecdbfa09e3 (patch)
treeb24f4943e57154c469c3a3de1c1ce5bbd0e5f084
parentc2d5d9c3a0c44f449879dd1c7ac9953a17733d2f (diff)
downloadsonarqube-e1d9aa49cb8f8fff3b17d884e008f6ecdbfa09e3.tar.gz
sonarqube-e1d9aa49cb8f8fff3b17d884e008f6ecdbfa09e3.zip
SONAR-3755 Add Issue Web Service Client
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/issue/IssueMapper.xml2
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/Issue.java196
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/IssueQuery.java180
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/IssueQueryTest.java60
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/IssueTest.java70
5 files changed, 507 insertions, 1 deletions
diff --git a/sonar-core/src/main/resources/org/sonar/core/issue/IssueMapper.xml b/sonar-core/src/main/resources/org/sonar/core/issue/IssueMapper.xml
index dde4f0c2cac..2ecc8510db0 100644
--- a/sonar-core/src/main/resources/org/sonar/core/issue/IssueMapper.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/issue/IssueMapper.xml
@@ -121,7 +121,7 @@
</if>
<if test="status != null">
and i.status in
- <foreach item="statu" index="index" collection="status" open="(" separator="," close=")">#{statu}
+ <foreach item="stat" index="index" collection="status" open="(" separator="," close=")">#{stat}
</foreach>
</if>
<if test="resolutions != null">
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Issue.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Issue.java
new file mode 100644
index 00000000000..7dc65fdfdca
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Issue.java
@@ -0,0 +1,196 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+import java.util.Date;
+
+/**
+ * @since 3.6
+ */
+public class Issue extends Model {
+
+ private String key;
+ private String componentKey;
+ private String ruleKey;
+ private String ruleRepositoryKey;
+ private String severity;
+ private String title;
+ private String message;
+ private Integer line;
+ private Double cost;
+ private String status;
+ private String resolution;
+ private String userLogin;
+ private String assigneeLogin;
+ private Date createdAt;
+ private Date updatedAt;
+ private Date closedAt;
+
+ public String getKey() {
+ return key;
+ }
+
+ public Issue setKey(String key) {
+ this.key = key;
+ return this;
+ }
+
+ public String getComponentKey() {
+ return componentKey;
+ }
+
+ public Issue setComponentKey(String componentKey) {
+ this.componentKey = componentKey;
+ return this;
+ }
+
+ public String getRuleKey() {
+ return ruleKey;
+ }
+
+ public Issue setRuleKey(String ruleKey) {
+ this.ruleKey = ruleKey;
+ return this;
+ }
+
+ public String getRuleRepositoryKey() {
+ return ruleRepositoryKey;
+ }
+
+ public Issue setRuleRepositoryKey(String ruleRepositoryKey) {
+ this.ruleRepositoryKey = ruleRepositoryKey;
+ return this;
+ }
+
+ public String getSeverity() {
+ return severity;
+ }
+
+ public Issue setSeverity(String severity) {
+ this.severity = severity;
+ return this;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public Issue setTitle(String title) {
+ this.title = title;
+ return this;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public Issue setMessage(String message) {
+ this.message = message;
+ return this;
+ }
+
+ public Integer getLine() {
+ return line;
+ }
+
+ public Issue setLine(Integer line) {
+ this.line = line;
+ return this;
+ }
+
+ public Double getCost() {
+ return cost;
+ }
+
+ public Issue setCost(Double cost) {
+ this.cost = cost;
+ return this;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public Issue setStatus(String status) {
+ this.status = status;
+ return this;
+ }
+
+ public String getResolution() {
+ return resolution;
+ }
+
+ public Issue setResolution(String resolution) {
+ this.resolution = resolution;
+ return this;
+ }
+
+ public String getUserLogin() {
+ return userLogin;
+ }
+
+ public Issue setUserLogin(String userLogin) {
+ this.userLogin = userLogin;
+ return this;
+ }
+
+ public String getAssigneeLogin() {
+ return assigneeLogin;
+ }
+
+ public Issue setAssigneeLogin(String assigneeLogin) {
+ this.assigneeLogin = assigneeLogin;
+ return this;
+ }
+
+ public Date getCreatedAt() {
+ return createdAt;
+ }
+
+ public Issue setCreatedAt(Date createdAt) {
+ this.createdAt = createdAt;
+ return this;
+ }
+
+ public Date getUpdatedAt() {
+ return updatedAt;
+ }
+
+ public Issue setUpdatedAt(Date updatedAt) {
+ this.updatedAt = updatedAt;
+ return this;
+ }
+
+ public Date getClosedAt() {
+ return closedAt;
+ }
+
+ public Issue setClosedAt(Date closedAt) {
+ this.closedAt = closedAt;
+ return this;
+ }
+
+ @Override
+ public String toString() {
+ return new StringBuilder()
+ .append(key)
+ .toString();
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/IssueQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/IssueQuery.java
new file mode 100644
index 00000000000..faee242c8fa
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/IssueQuery.java
@@ -0,0 +1,180 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+/**
+ * @since 3.6
+ */
+public final class IssueQuery extends Query<Issue> {
+
+ public static final String BASE_URL = "/api/issues";
+
+ private String key;
+ private String[] keys;
+ private String[] severities;
+ private String minSeverity;
+ private String[] status;
+ private String[] resolutions;
+ private String[] components;
+ private String[] rules;
+ private String[] userLogins;
+ private String[] assigneeLogins;
+ private Integer limit;
+
+ private IssueQuery() {
+ }
+
+ public static String getBaseUrl() {
+ return BASE_URL;
+ }
+
+ public static IssueQuery create() {
+ return new IssueQuery();
+ }
+
+ public static IssueQuery byKey(String key) {
+ return new IssueQuery().setKey(key);
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public IssueQuery setKey(String key) {
+ this.key = key;
+ return this;
+ }
+
+ public String[] getKeys() {
+ return keys;
+ }
+
+ public IssueQuery setKeys(String... keys) {
+ this.keys = keys;
+ return this;
+ }
+
+ public String[] getSeverities() {
+ return severities;
+ }
+
+ public IssueQuery setSeverities(String... severities) {
+ this.severities = severities;
+ return this;
+ }
+
+ public String getMinSeverity() {
+ return minSeverity;
+ }
+
+ public IssueQuery setMinSeverity(String minSeverity) {
+ this.minSeverity = minSeverity;
+ return this;
+ }
+
+ public String[] getStatus() {
+ return status;
+ }
+
+ public IssueQuery setStatus(String... status) {
+ this.status = status;
+ return this;
+ }
+
+ public String[] getResolutions() {
+ return resolutions;
+ }
+
+ public IssueQuery setResolutions(String... resolutions) {
+ this.resolutions = resolutions;
+ return this;
+ }
+
+ public String[] getComponents() {
+ return components;
+ }
+
+ public IssueQuery setComponents(String... components) {
+ this.components = components;
+ return this;
+ }
+
+ public String[] getRules() {
+ return rules;
+ }
+
+ public IssueQuery setRules(String... rules) {
+ this.rules = rules;
+ return this;
+ }
+
+ public String[] getUserLogins() {
+ return userLogins;
+ }
+
+ public IssueQuery setUserLogins(String... userLogins) {
+ this.userLogins = userLogins;
+ return this;
+ }
+
+ public String[] getAssigneeLogins() {
+ return assigneeLogins;
+ }
+
+ public IssueQuery setAssigneeLogins(String... assigneeLogins) {
+ this.assigneeLogins = assigneeLogins;
+ return this;
+ }
+
+ public Integer getLimit() {
+ return limit;
+ }
+
+ public IssueQuery setLimit(Integer limit) {
+ this.limit = limit;
+ return this;
+ }
+
+ @Override
+ public String getUrl() {
+ StringBuilder url = new StringBuilder(BASE_URL);
+ if (key != null && !"".equals(key)) {
+ url.append("/");
+ url.append(encode(key));
+ }
+ url.append('?');
+ appendUrlParameter(url, "keys", keys);
+ appendUrlParameter(url, "severities", severities);
+ appendUrlParameter(url, "minSeverity", minSeverity);
+ appendUrlParameter(url, "status", status);
+ appendUrlParameter(url, "resolutions", resolutions);
+ appendUrlParameter(url, "components", components);
+ appendUrlParameter(url, "rules", rules);
+ appendUrlParameter(url, "userLogins", userLogins);
+ appendUrlParameter(url, "assigneeLogins", assigneeLogins);
+ appendUrlParameter(url, "limit", limit);
+ return url.toString();
+ }
+
+ @Override
+ public Class<Issue> getModelClass() {
+ return Issue.class;
+ }
+}
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/IssueQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/IssueQueryTest.java
new file mode 100644
index 00000000000..180af81f149
--- /dev/null
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/IssueQueryTest.java
@@ -0,0 +1,60 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+
+package org.sonar.wsclient.services;
+
+import org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class IssueQueryTest extends QueryTestCase {
+
+ @Test
+ public void get_all_issues() {
+ IssueQuery query = IssueQuery.create();
+ assertThat(query.getUrl()).isEqualTo("/api/issues?");
+ }
+
+ @Test
+ public void get_all_issues_by_parameter() {
+ IssueQuery query = IssueQuery.create()
+ .setKeys("key1", "key2")
+ .setAssigneeLogins("assigneeLogin1", "assigneeLogin2")
+ .setComponents("component1", "component2")
+ .setLimit(1)
+ .setMinSeverity("minSev")
+ .setResolutions("resoltion1", "resolution2")
+ .setRules("rule1", "rule2")
+ .setStatus("status1", "status2")
+ .setSeverities("sev1", "sev2")
+ .setUserLogins("userLogin1", "userLogin2");
+ assertThat(query.getUrl()).isEqualTo("/api/issues?keys=key1,key2&severities=sev1,sev2&minSeverity=minSev&status=status1,status2&" +
+ "resolutions=resoltion1,resolution2&components=component1,component2&rules=rule1,rule2&userLogins=userLogin1,userLogin2&" +
+ "assigneeLogins=assigneeLogin1,assigneeLogin2&limit=1&");
+ }
+
+ @Test
+ public void get_issue_by_key() {
+ IssueQuery query = IssueQuery.byKey("issue_key");
+ assertThat(query.getUrl()).isEqualTo("/api/issues/issue_key?");
+ assertThat(query.getKey()).isEqualTo("issue_key");
+ }
+
+}
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/IssueTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/IssueTest.java
new file mode 100644
index 00000000000..33fc868b808
--- /dev/null
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/IssueTest.java
@@ -0,0 +1,70 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+
+package org.sonar.wsclient.services;
+
+import org.junit.Test;
+
+import java.util.Date;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class IssueTest {
+
+ @Test
+ public void test_getter_and_setter() {
+ Issue issue = new Issue()
+ .setKey("key")
+ .setComponentKey("componentKey")
+ .setRuleKey("ruleKey")
+ .setRuleRepositoryKey("ruleRepositoryKey")
+ .setSeverity("severity")
+ .setTitle("title")
+ .setMessage("message")
+ .setLine(1)
+ .setCost(1.0)
+ .setStatus("status")
+ .setResolution("resolution")
+ .setUserLogin("userLogin")
+ .setAssigneeLogin("assigneeLogin")
+ .setCreatedAt(new Date())
+ .setUpdatedAt(new Date())
+ .setClosedAt(new Date());
+
+ assertThat(issue.getKey()).isNotNull();
+ assertThat(issue.getComponentKey()).isNotNull();
+ assertThat(issue.getRuleKey()).isNotNull();
+ assertThat(issue.getRuleRepositoryKey()).isNotNull();
+ assertThat(issue.getSeverity()).isNotNull();
+ assertThat(issue.getTitle()).isNotNull();
+ assertThat(issue.getMessage()).isNotNull();
+ assertThat(issue.getLine()).isNotNull();
+ assertThat(issue.getCost()).isNotNull();
+ assertThat(issue.getStatus()).isNotNull();
+ assertThat(issue.getResolution()).isNotNull();
+ assertThat(issue.getUserLogin()).isNotNull();
+ assertThat(issue.getAssigneeLogin()).isNotNull();
+ assertThat(issue.getCreatedAt()).isNotNull();
+ assertThat(issue.getUpdatedAt()).isNotNull();
+ assertThat(issue.getClosedAt()).isNotNull();
+
+ }
+
+}