private final Boolean assigned;
private final Boolean planned;
private final Boolean resolved;
+ private final Boolean hideRules;
private final Date createdAt;
private final Date createdAfter;
private final Date createdBefore;
this.assigned = builder.assigned;
this.planned = builder.planned;
this.resolved = builder.resolved;
+ this.hideRules = builder.hideRules;
this.createdAt = builder.createdAt;
this.createdAfter = builder.createdAfter;
this.createdBefore = builder.createdBefore;
return resolved;
}
+ /**
+ * @since 4.2
+ */
+ @CheckForNull
+ public Boolean hideRules() {
+ return hideRules;
+ }
+
@CheckForNull
public Date createdAfter() {
return createdAfter == null ? null : new Date(createdAfter.getTime());
private Boolean assigned = null;
private Boolean planned = null;
private Boolean resolved = null;
+ private Boolean hideRules = false;
private Date createdAt;
private Date createdAfter;
private Date createdBefore;
return this;
}
+ /**
+ * If true, rules will not be loaded
+ * If false, rules will be loaded
+ *
+ * @since 4.2
+ *
+ */
+ public Builder hideRules(@Nullable Boolean b) {
+ this.hideRules = b;
+ return this;
+ }
+
public Builder createdAt(@Nullable Date d) {
this.createdAt = d == null ? null : new Date(d.getTime());
return this;
public class IssueQueryTest {
@Test
- public void should_build_query() throws Exception {
+ public void build_query() throws Exception {
IssueQuery query = IssueQuery.builder()
.issueKeys(newArrayList("ABCDE"))
.severities(newArrayList(Severity.BLOCKER))
.reporters(newArrayList("crunky"))
.assignees(newArrayList("gargantua"))
.assigned(true)
+ .hideRules(true)
.createdAfter(new Date())
.createdBefore(new Date())
.createdAt(new Date())
assertThat(query.reporters()).containsOnly("crunky");
assertThat(query.assignees()).containsOnly("gargantua");
assertThat(query.assigned()).isTrue();
+ assertThat(query.hideRules()).isTrue();
assertThat(query.rules()).containsOnly(RuleKey.of("squid", "AvoidCycle"));
assertThat(query.actionPlans()).containsOnly("AP1", "AP2");
assertThat(query.createdAfter()).isNotNull();
}
@Test
- public void should_build_query_without_dates() throws Exception {
+ public void build_query_without_dates() throws Exception {
IssueQuery query = IssueQuery.builder()
.issueKeys(newArrayList("ABCDE"))
.createdAfter(null)
}
@Test
- public void should_throw_exception_if_sort_is_not_valid() throws Exception {
+ public void throw_exception_if_sort_is_not_valid() throws Exception {
try {
IssueQuery.builder()
.sort("UNKNOWN")
}
@Test
- public void should_use_max_page_size_if_negative() throws Exception {
+ public void use_max_page_size_if_negative() throws Exception {
IssueQuery query = IssueQuery.builder().pageSize(0).build();
assertThat(query.pageSize()).isEqualTo(IssueQuery.MAX_PAGE_SIZE);
}
@Test
- public void should_reset_to_max_page_size() throws Exception {
+ public void reset_to_max_page_size() throws Exception {
IssueQuery query = IssueQuery.builder()
.pageSize(IssueQuery.MAX_PAGE_SIZE + 100)
.build();
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.component.Component;
-import org.sonar.api.issue.ActionPlan;
-import org.sonar.api.issue.Issue;
-import org.sonar.api.issue.IssueFinder;
-import org.sonar.api.issue.IssueQuery;
-import org.sonar.api.issue.IssueQueryResult;
+import org.sonar.api.issue.*;
import org.sonar.api.issue.internal.DefaultIssue;
import org.sonar.api.issue.internal.DefaultIssueComment;
import org.sonar.api.rules.Rule;
import org.sonar.core.rule.DefaultRuleFinder;
import org.sonar.server.user.UserSession;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Maps.newHashMap;
}
}
+
return new DefaultIssueQueryResult(issues)
.setMaxResultsReached(authorizedIssues.size() == query.maxResults())
- .addRules(findRules(ruleIds))
+ .addRules(hideRules(query) ? Collections.<Rule>emptyList() : findRules(ruleIds))
.addComponents(findComponents(componentIds))
.addProjects(findComponents(projectIds))
.addActionPlans(findActionPlans(actionPlanKeys))
}
}
+ private boolean hideRules(IssueQuery query){
+ Boolean hideRules = query.hideRules();
+ return hideRules != null ? hideRules : false;
+ }
+
private List<IssueDto> sort(List<IssueDto> issues, IssueQuery query, int allIssuesSize) {
if (allIssuesSize < query.maxResults()) {
return new IssuesFinderSort(issues, query).sort();
.assignees(RubyUtils.toStrings(props.get(IssueFilterParameters.ASSIGNEES)))
.assigned(RubyUtils.toBoolean(props.get(IssueFilterParameters.ASSIGNED)))
.planned(RubyUtils.toBoolean(props.get(IssueFilterParameters.PLANNED)))
+ .hideRules(RubyUtils.toBoolean(props.get(IssueFilterParameters.HIDE_RULES)))
.createdAt(RubyUtils.toDate(props.get(IssueFilterParameters.CREATED_AT)))
.createdAfter(RubyUtils.toDate(props.get(IssueFilterParameters.CREATED_AFTER)))
.createdBefore(RubyUtils.toDate(props.get(IssueFilterParameters.CREATED_BEFORE)))
public static final String ASSIGNEES = "assignees";
public static final String ASSIGNED = "assigned";
public static final String PLANNED = "planned";
+ public static final String HIDE_RULES = "hideRules";
public static final String CREATED_AFTER = "createdAfter";
public static final String CREATED_AT = "createdAt";
public static final String CREATED_BEFORE = "createdBefore";
public static final String ASC = "asc";
public static final List<String> ALL = ImmutableList.of(ISSUES, SEVERITIES, STATUSES, RESOLUTIONS, RESOLVED, COMPONENTS, COMPONENT_ROOTS, RULES, ACTION_PLANS, REPORTERS,
- ASSIGNEES, ASSIGNED, PLANNED, CREATED_AT, CREATED_AFTER, CREATED_BEFORE, PAGE_SIZE, PAGE_INDEX, SORT, ASC);
+ ASSIGNEES, ASSIGNED, PLANNED, HIDE_RULES, CREATED_AT, CREATED_AFTER, CREATED_BEFORE, PAGE_SIZE, PAGE_INDEX, SORT, ASC);
public static final List<String> ALL_WITHOUT_PAGINATION = newArrayList(Iterables.filter(ALL, new Predicate<String>() {
@Override
hash = {
:maxResultsReached => results.maxResultsReached,
:paging => paging_to_hash(results.paging),
- :issues => results.issues.map { |issue| Issue.to_hash(issue, results.rule(issue).name) },
+ :issues => results.issues.map { |issue| Issue.to_hash(issue, results.rule(issue) ? results.rule(issue).name : nil) },
:components => results.components.map { |component| component_to_hash(component) },
:projects => results.projects.map { |project| component_to_hash(project) },
:rules => results.rules.map { |rule| Rule.to_hash(rule) },
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
public class DefaultIssueFinderTest {
DefaultIssueFinder finder = new DefaultIssueFinder(mybatis, issueDao, issueChangeDao, ruleFinder, userFinder, resourceDao, actionPlanService);
@Test
- public void should_find_issues() {
+ public void find_issues() {
IssueQuery query = IssueQuery.builder().build();
IssueDto issue1 = new IssueDto().setId(1L).setRuleId(50).setComponentId(123l).setRootComponentId(100l)
}
@Test
- public void should_find_paginate_result() {
+ public void find_paginate_result() {
IssueQuery query = IssueQuery.builder().pageSize(1).pageIndex(1).build();
IssueDto issue1 = new IssueDto().setId(1L).setRuleId(50).setComponentId(123l).setRootComponentId(100l)
}
@Test
- public void should_find_by_key() {
+ public void find_by_key() {
IssueDto issueDto = new IssueDto().setId(1L).setRuleId(1).setComponentId(1l).setRootComponentId(100l)
.setComponentKey_unit_test_only("Action.java")
.setRootComponentKey_unit_test_only("struts")
}
@Test
- public void should_get_rule_from_result() {
+ public void get_rule_from_result() {
Rule rule = Rule.create().setRepositoryKey("squid").setKey("AvoidCycle");
when(ruleFinder.findByIds(anyCollection())).thenReturn(newArrayList(rule));
}
@Test
- public void should_get_component_from_result() {
+ public void get_no_rule_from_result_with_hide_rules_param() {
+ Rule rule = Rule.create().setRepositoryKey("squid").setKey("AvoidCycle");
+ when(ruleFinder.findByIds(anyCollection())).thenReturn(newArrayList(rule));
+
+ IssueQuery query = IssueQuery.builder().hideRules(true).build();
+
+ IssueDto issue = new IssueDto().setId(1L).setRuleId(50).setComponentId(123l).setRootComponentId(100l)
+ .setComponentKey_unit_test_only("Action.java")
+ .setRootComponentKey_unit_test_only("struts")
+ .setRuleKey_unit_test_only("squid", "AvoidCycle")
+ .setStatus("OPEN").setResolution("OPEN");
+ when(issueDao.selectByIds(anyCollection(), any(SqlSession.class))).thenReturn(newArrayList(issue));
+
+ IssueQueryResult results = finder.find(query);
+ Issue result = results.issues().iterator().next();
+ assertThat(results.rule(result)).isNull();
+ assertThat(results.rules()).isEmpty();
+ }
+
+ @Test
+ public void get_component_from_result() {
Component component = new ComponentDto().setKey("Action.java");
when(resourceDao.findByIds(anyCollection())).thenReturn(newArrayList(component));
}
@Test
- public void should_get_project_from_result() {
+ public void get_project_from_result() {
Component project = new ComponentDto().setKey("struts");
when(resourceDao.findByIds(anyCollection())).thenReturn(newArrayList(project));
}
@Test
- public void should_get_action_plans_from_result() {
+ public void get_action_plans_from_result() {
ActionPlan actionPlan1 = DefaultActionPlan.create("Short term").setKey("A");
ActionPlan actionPlan2 = DefaultActionPlan.create("Long term").setKey("B");
}
@Test
- public void should_get_user_from_result() {
+ public void get_user_from_result() {
when(userFinder.findByLogins(anyListOf(String.class))).thenReturn(Lists.<User>newArrayList(
new DefaultUser().setLogin("perceval").setName("Perceval"),
new DefaultUser().setLogin("arthur").setName("Roi Arthur")
}
@Test
- public void should_get_empty_result_when_no_issue() {
+ public void get_empty_result_when_no_issue() {
IssueQuery query = IssueQuery.builder().build();
when(issueDao.selectIssueIds(eq(query), anyInt(), any(SqlSession.class))).thenReturn(Collections.<IssueDto>emptyList());
when(issueDao.selectByIds(anyCollection(), any(SqlSession.class))).thenReturn(Collections.<IssueDto>emptyList());
}
@Test
- public void should_find_issue_with_technical_debt() {
+ public void find_issue_with_technical_debt() {
IssueQuery query = IssueQuery.builder().build();
IssueDto issue = new IssueDto().setId(1L).setRuleId(50).setComponentId(123l).setRootComponentId(100l)
}
@Test
- public void should_create_query_from_parameters() {
+ public void create_query_from_parameters() {
Map<String, Object> map = newHashMap();
map.put("issues", newArrayList("ABCDE1234"));
map.put("severities", newArrayList("MAJOR", "MINOR"));
map.put("assignees", newArrayList("joanna"));
map.put("assigned", true);
map.put("planned", true);
+ map.put("hideRules", 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");
assertThat(query.assignees()).containsOnly("joanna");
assertThat(query.assigned()).isTrue();
assertThat(query.planned()).isTrue();
+ assertThat(query.hideRules()).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"));
return this;
}
+ /**
+ * @since 4.2
+ */
+ public IssueQuery hideRules(Boolean hideRules) {
+ params.put("hideRules", hideRules);
+ return this;
+ }
+
/**
* Require second precision.
* @since 3.7
.componentRoots("struts")
.resolutions("FIXED", "FALSE-POSITIVE")
.resolved(true)
+ .hideRules(true)
.rules("squid:AvoidCycle")
.actionPlans("ABC")
.statuses("OPEN", "CLOSED")
.pageSize(5)
.pageIndex(4);
- assertThat(query.urlParams()).hasSize(20);
+ assertThat(query.urlParams()).hasSize(21);
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("actionPlans", "ABC"));
assertThat(query.urlParams()).includes(entry("resolutions", "FIXED,FALSE-POSITIVE"));
assertThat(query.urlParams()).includes(entry("resolved", true));
+ assertThat(query.urlParams()).includes(entry("hideRules", true));
assertThat(query.urlParams()).includes(entry("statuses", "OPEN,CLOSED"));
assertThat(query.urlParams()).includes(entry("severities", "BLOCKER,INFO"));
assertThat(query.urlParams()).includes(entry("reporters", "login1,login2"));