]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3755 Add assigned parameter to IssueQuery
authorJulien Lancelot <julien.lancelot@gmail.com>
Tue, 30 Apr 2013 14:17:58 +0000 (16:17 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Tue, 30 Apr 2013 14:17:58 +0000 (16:17 +0200)
sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml
sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java
sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_assigned.xml [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java
sonar-plugin-api/src/test/java/org/sonar/api/issue/IssueQueryTest.java
sonar-server/src/main/java/org/sonar/server/issue/JRubyApiIssues.java
sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb
sonar-server/src/test/java/org/sonar/server/issue/JRubyApiIssuesTest.java
sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueQuery.java
sonar-ws-client/src/test/java/org/sonar/wsclient/issue/IssueQueryTest.java

index 6af9a54713f6a3c249a9944a42be6b72357d08c3..a8ade541e18cebd62f766e9264aa835ba27da797 100644 (file)
         <foreach item="assignee" index="index" collection="assignees" open="(" separator="," close=")">#{assignee}
         </foreach>
       </if>
+      <if test="assigned != null">
+        <if test="assigned == true">
+          and i.assignee_login is not null
+        </if>
+        <if test="assigned == false">
+          and i.assignee_login is null
+        </if>
+      </if>
       <if test="rules != null and rules.size() > 0">
         and (<foreach item="rule" index="index" collection="rules" open="(" separator=" or " close=")">r.plugin_name=#{rule.repository} and r.plugin_rule_key=#{rule.rule}</foreach>)
       </if>
index 31814746935e48967d6f7a0e54696c8ec270dcda..e988b9c2bd90d39f34cd834f50922aef02df52c9 100644 (file)
@@ -201,6 +201,23 @@ public class IssueDaoTest extends AbstractDaoTestCase {
     assertThat(issues).isEmpty();
   }
 
+  @Test
+  public void should_select_by_assigned() {
+    setupData("shared", "should_select_by_assigned");
+
+    IssueQuery query = IssueQuery.builder().assigned(true).build();
+    List<IssueDto> issues = newArrayList(dao.select(query));
+    assertThat(issues).hasSize(2);
+
+    query = IssueQuery.builder().assigned(false).build();
+    issues = newArrayList(dao.select(query));
+    assertThat(issues).hasSize(1);
+
+    query = IssueQuery.builder().assigned(null).build();
+    issues = newArrayList(dao.select(query));
+    assertThat(issues).hasSize(3);
+  }
+
   @Test
   public void should_select_all() {
     setupData("shared", "should_select_all");
@@ -251,5 +268,4 @@ public class IssueDaoTest extends AbstractDaoTestCase {
     assertThat(results).hasSize(3);
   }
 
-
 }
diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_assigned.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_assigned.xml
new file mode 100644 (file)
index 0000000..84bc4cd
--- /dev/null
@@ -0,0 +1,74 @@
+<dataset>
+
+  <!-- rule 500 -->
+  <issues
+      id="100"
+      kee="ABCDE"
+      resource_id="400"
+      rule_id="500"
+      severity="BLOCKER"
+      manual_severity="[false]"
+      manual_issue="[false]"
+      description="[null]"
+      line="200"
+      cost="4.2"
+      status="OPEN"
+      resolution="FIXED"
+      checksum="XXX"
+      user_login="arthur"
+      assignee_login="perceval"
+      author_login="[null]"
+      attributes="JIRA=FOO-1234"
+      created_at="2013-04-16"
+      updated_at="2013-04-16"
+      closed_at="2013-04-16"
+      />
+
+  <issues
+      id="101"
+      kee="ABCDE"
+      resource_id="400"
+      rule_id="500"
+      severity="BLOCKER"
+      manual_severity="[false]"
+      manual_issue="[false]"
+      description="[null]"
+      line="200"
+      cost="4.2"
+      status="OPEN"
+      resolution="FIXED"
+      checksum="XXX"
+      user_login="arthur"
+      assignee_login="perceval"
+      author_login="[null]"
+      attributes="JIRA=FOO-1234"
+      created_at="2013-04-16"
+      updated_at="2013-04-16"
+      closed_at="2013-04-16"
+      />
+
+
+  <!-- rule 501 -->
+  <issues
+      id="102"
+      kee="ABCDE"
+      resource_id="400"
+      rule_id="501"
+      severity="BLOCKER"
+      manual_severity="[false]"
+      manual_issue="[false]"
+      description="[null]"
+      line="200"
+      cost="4.2"
+      status="OPEN"
+      resolution="FIXED"
+      checksum="XXX"
+      user_login="arthur"
+      assignee_login="[null]"
+      author_login="[null]"
+      attributes="JIRA=FOO-1234"
+      created_at="2013-04-16"
+      updated_at="2013-04-16"
+      closed_at="2013-04-16"
+      />
+</dataset>
index b480b29b39f19d571d4145ae0629560cd1d41e41..796a6d42df7403416e8641ccef2f9d2422a84258 100644 (file)
@@ -46,6 +46,7 @@ public class IssueQuery {
   private final Collection<RuleKey> rules;
   private final Collection<String> userLogins;
   private final Collection<String> assignees;
+  private final Boolean assigned;
   private final Date createdAfter;
   private final Date createdBefore;
   private final String sort;
@@ -67,6 +68,7 @@ public class IssueQuery {
     this.rules = builder.rules;
     this.userLogins = builder.userLogins;
     this.assignees = builder.assignees;
+    this.assigned = builder.assigned;
     this.createdAfter = builder.createdAfter;
     this.createdBefore = builder.createdBefore;
     this.sort = builder.sort;
@@ -111,6 +113,10 @@ public class IssueQuery {
     return assignees;
   }
 
+  public Boolean assigned() {
+    return assigned;
+  }
+
   public Date createdAfter() {
     return createdAfter;
   }
@@ -167,6 +173,7 @@ public class IssueQuery {
     private Collection<RuleKey> rules;
     private Collection<String> userLogins;
     private Collection<String> assignees;
+    private Boolean assigned = null;
     private Date createdAfter;
     private Date createdBefore;
     private String sort;
@@ -222,6 +229,15 @@ public class IssueQuery {
       return this;
     }
 
+    /**
+     * If true, it will return all issues assigned to someone
+     * If false, it will return all issues not assigned to someone
+     */
+    public Builder assigned(Boolean assigned) {
+      this.assigned = assigned;
+      return this;
+    }
+
     public Builder createdAfter(Date createdAfter) {
       this.createdAfter = createdAfter;
       return this;
index 484119de21dddfcae3e055a21dfed427a83db1e2..5a9d955bac1ee701acd32f3713fd8ee081183b15 100644 (file)
@@ -43,6 +43,7 @@ public class IssueQueryTest {
       .rules(Lists.newArrayList(RuleKey.of("squid", "AvoidCycle")))
       .userLogins(Lists.newArrayList("crunky"))
       .assignees(Lists.newArrayList("gargantua"))
+      .assigned(true)
       .createdAfter(new Date())
       .createdBefore(new Date())
       .sort("assignee")
@@ -57,6 +58,7 @@ public class IssueQueryTest {
     assertThat(query.componentRoots()).containsOnly("org.struts:core");
     assertThat(query.userLogins()).containsOnly("crunky");
     assertThat(query.assignees()).containsOnly("gargantua");
+    assertThat(query.assigned()).isTrue();
     assertThat(query.rules()).containsOnly(RuleKey.of("squid", "AvoidCycle"));
     assertThat(query.createdAfter()).isNotNull();
     assertThat(query.createdBefore()).isNotNull();
index 6dba7311d733e645109b9c8a435bd4248be3eb3f..c1170d27577f51df373ac713958f440ffb5137f6 100644 (file)
@@ -72,6 +72,7 @@ public class JRubyApiIssues implements JRubyIssues {
     builder.rules(toRules(props.get("rules")));
     builder.userLogins(toStrings(props.get("userLogins")));
     builder.assignees(toStrings(props.get("assignees")));
+    builder.assigned(toBoolean(props.get("assigned")));
     builder.createdAfter(toDate(props.get("createdAfter")));
     builder.createdBefore(toDate(props.get("createdBefore")));
     builder.pageSize(toInteger(props.get("pageSize")));
@@ -150,6 +151,16 @@ public class JRubyApiIssues implements JRubyIssues {
     return null;
   }
 
+  Boolean toBoolean(Object o) {
+    if (o instanceof Boolean) {
+      return (Boolean) o;
+    }
+    if (o instanceof String) {
+      return Boolean.parseBoolean((String) o);
+    }
+    return null;
+  }
+
   public void start() {
     // used to force pico to instantiate the singleton at startup
   }
index 37aa7896bb384388c56d66aeb5b22bb58d23b420..c798bf21073cc8ac6fbc5d9ef520a4d85fdb9e85 100644 (file)
@@ -431,8 +431,7 @@ class ResourceController < ApplicationController
         options['statuses'] = ['RESOLVED']
 
       elsif rule_param=='unassigned_issues'
-        # FIXME 'assignees' to nil will always return all issues!
-        options['assignees'] = nil
+        options['assigned'] = false
 
       # TODO
       #elsif rule_param=='unplanned_reviews'
index 55f651ec207f3458f14e16f15e4efeb42b492b7d..ed742c876b8f5cb2de82b25d4c05a2f23fb2787f 100644 (file)
@@ -66,6 +66,7 @@ public class JRubyApiIssuesTest {
     map.put("componentRoots", newArrayList("org.sonar"));
     map.put("userLogins", newArrayList("marilyn"));
     map.put("assignees", newArrayList("joanna"));
+    map.put("assigned", true);
     map.put("createdAfter", "2013-04-16T09:08:24+0200");
     map.put("createdBefore", "2013-04-17T09:08:24+0200");
     map.put("rules", "squid:AvoidCycle,findbugs:NullReference");
@@ -81,6 +82,7 @@ public class JRubyApiIssuesTest {
     assertThat(query.componentRoots()).containsOnly("org.sonar");
     assertThat(query.userLogins()).containsOnly("marilyn");
     assertThat(query.assignees()).containsOnly("joanna");
+    assertThat(query.assigned()).isTrue();
     assertThat(query.rules()).hasSize(2);
     assertThat(query.createdAfter()).isEqualTo(DateUtils.parseDateTime("2013-04-16T09:08:24+0200"));
     assertThat(query.createdBefore()).isEqualTo(DateUtils.parseDateTime("2013-04-17T09:08:24+0200"));
index dea74706900c0cbff35193849e53d17c3b3f14d4..5589f5c7ee74d653417da42cd8bee6e179a592bc 100644 (file)
@@ -80,6 +80,11 @@ public class IssueQuery {
     return addParam("assignees", s);
   }
 
+  public IssueQuery assigned(Boolean assigned) {
+    params.put("assigned", assigned);
+    return this;
+  }
+
   public IssueQuery createdAfter(Date d) {
     params.put("createdAfter", EncodingUtils.toQueryParam(d, true));
     return this;
index de00cb0af06d259029f25020173ff126be70abbb..cffe192920d6675102ba17d3061335e00041ad12 100644 (file)
@@ -36,6 +36,7 @@ public class IssueQueryTest {
     IssueQuery query = IssueQuery.create()
       .issues("ABCDE", "FGHIJ")
       .assignees("arthur", "perceval")
+      .assigned(true)
       .components("Action.java", "Filter.java")
       .componentRoots("struts")
       .resolutions("FIXED", "FALSE-POSITIVE")
@@ -48,9 +49,10 @@ public class IssueQueryTest {
       .pageSize(5)
       .pageIndex(4);
 
-    assertThat(query.urlParams()).hasSize(13);
+    assertThat(query.urlParams()).hasSize(14);
     assertThat(query.urlParams()).includes(entry("issues", "ABCDE,FGHIJ"));
     assertThat(query.urlParams()).includes(entry("assignees", "arthur,perceval"));
+    assertThat(query.urlParams()).includes(entry("assigned", true));
     assertThat(query.urlParams()).includes(entry("components", "Action.java,Filter.java"));
     assertThat(query.urlParams()).includes(entry("componentRoots", "struts"));
     assertThat(query.urlParams()).includes(entry("resolutions", "FIXED,FALSE-POSITIVE"));