diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2013-04-30 16:17:58 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2013-04-30 16:17:58 +0200 |
commit | 65a6f6d2484de42c29972fb5d34e41dba84e8692 (patch) | |
tree | 8f64739f58ab6768bf437c8d448b017cadcf1dec | |
parent | 238f713bf3d10a388f2bbabf1163008f95e15e67 (diff) | |
download | sonarqube-65a6f6d2484de42c29972fb5d34e41dba84e8692.tar.gz sonarqube-65a6f6d2484de42c29972fb5d34e41dba84e8692.zip |
SONAR-3755 Add assigned parameter to IssueQuery
10 files changed, 139 insertions, 4 deletions
diff --git a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml index 6af9a54713f..a8ade541e18 100644 --- a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml @@ -196,6 +196,14 @@ <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> diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java index 31814746935..e988b9c2bd9 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java @@ -202,6 +202,23 @@ public class IssueDaoTest extends AbstractDaoTestCase { } @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 index 00000000000..84bc4cd36c5 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_assigned.xml @@ -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> diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java index b480b29b39f..796a6d42df7 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java @@ -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; diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/issue/IssueQueryTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/issue/IssueQueryTest.java index 484119de21d..5a9d955bac1 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/issue/IssueQueryTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/issue/IssueQueryTest.java @@ -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(); diff --git a/sonar-server/src/main/java/org/sonar/server/issue/JRubyApiIssues.java b/sonar-server/src/main/java/org/sonar/server/issue/JRubyApiIssues.java index 6dba7311d73..c1170d27577 100644 --- a/sonar-server/src/main/java/org/sonar/server/issue/JRubyApiIssues.java +++ b/sonar-server/src/main/java/org/sonar/server/issue/JRubyApiIssues.java @@ -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 } diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb index 37aa7896bb3..c798bf21073 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb @@ -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' diff --git a/sonar-server/src/test/java/org/sonar/server/issue/JRubyApiIssuesTest.java b/sonar-server/src/test/java/org/sonar/server/issue/JRubyApiIssuesTest.java index 55f651ec207..ed742c876b8 100644 --- a/sonar-server/src/test/java/org/sonar/server/issue/JRubyApiIssuesTest.java +++ b/sonar-server/src/test/java/org/sonar/server/issue/JRubyApiIssuesTest.java @@ -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")); diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueQuery.java index dea74706900..5589f5c7ee7 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueQuery.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueQuery.java @@ -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; diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/IssueQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/IssueQueryTest.java index de00cb0af06..cffe192920d 100644 --- a/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/IssueQueryTest.java +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/IssueQueryTest.java @@ -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")); |