class ChangeDtoConverter {
+ private ChangeDtoConverter() {
+ // only static methods
+ }
+
static final String TYPE_FIELD_CHANGE = "change";
static final String TYPE_COMMENT = "comment";
private final MyBatis mybatis;
- private static final Map<String, String> SORTS = ImmutableMap.of(
- "created", "i.issue_creation_date",
- "updated", "i.issue_update_date",
- "closed", "i.issue_close_date",
- "assignee", "i.assignee"
- );
-
public IssueDao(MyBatis mybatis) {
this.mybatis = mybatis;
}
} else {
parent = new ResourcesClassloader(resources, baseClassloader);
}
- final ClassRealm realm;
+ ClassRealm realm;
if (plugin.isUseChildFirstClassLoader()) {
ClassRealm parentRealm = world.newRealm(plugin.getKey() + "-parent", parent);
realm = parentRealm.createChildRealm(plugin.getKey());
}
@VisibleForTesting
- protected HtmlSourceDecorator(SnapshotSourceDao snapshotSourceDao, SnapshotDataDao snapshotDataDao) {
+ HtmlSourceDecorator(SnapshotSourceDao snapshotSourceDao, SnapshotDataDao snapshotDataDao) {
this.snapshotSourceDao = snapshotSourceDao;
this.snapshotDataDao= snapshotDataDao;
}
<if test="sort != null">
order by
<choose>
- <when test="'created'.equals(sort)">
+ <when test="'CREATION_DATE'.equals(sort.name())">
i.issue_creation_date
</when>
- <when test="'updated'.equals(sort)">
+ <when test="'UPDATE_DATE'.equals(sort.name())">
i.issue_update_date
</when>
- <when test="'closed'.equals(sort)">
+ <when test="'CLOSE_DATE'.equals(sort.name())">
i.issue_close_date
</when>
- <when test="'assignee'.equals(sort)">
+ <when test="'ASSIGNEE'.equals(sort.name())">
i.assignee_login
</when>
</choose>
public void should_select_sort_by_assignee() {
setupData("shared", "should_select_returned_sorted_result");
- IssueQuery query = IssueQuery.builder().sort("assignee").asc(true).build();
- List<IssueDto> results = newArrayList(dao.select(query));
+ IssueQuery query = IssueQuery.builder().sort(IssueQuery.Sort.ASSIGNEE).asc(true).build();
+ List < IssueDto > results = newArrayList(dao.select(query));
assertThat(results).hasSize(3);
assertThat(results.get(0).getAssignee()).isEqualTo("arthur");
assertThat(results.get(1).getAssignee()).isEqualTo("henry");
import org.sonar.api.rule.RuleKey;
import javax.annotation.Nullable;
-
-import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
*/
public class IssueQuery {
+ public static enum Sort {
+ CREATION_DATE, UPDATE_DATE, CLOSE_DATE, ASSIGNEE
+ }
+
private final Collection<String> issueKeys;
private final Collection<String> severities;
private final Collection<String> statuses;
private final Boolean assigned;
private final Date createdAfter;
private final Date createdBefore;
- private final String sort;
+ private final Sort sort;
private final boolean asc;
// max results per page
return createdBefore;
}
- public String sort() {
+ public Sort sort() {
return sort;
}
*/
public static class Builder {
- private enum Sort {
- created, updated, closed, assignee
- }
-
private static final int DEFAULT_PAGE_SIZE = 100;
private static final int MAX_PAGE_SIZE = 1000;
private static final int DEFAULT_PAGE_INDEX = 1;
private Boolean assigned = null;
private Date createdAfter;
private Date createdBefore;
- private String sort;
+ private Sort sort;
private boolean asc = false;
private int pageSize = DEFAULT_PAGE_SIZE;
private int pageIndex = DEFAULT_PAGE_INDEX;
return this;
}
- public Builder sort(@Nullable String sort) {
- if (sort != null) {
- try {
- this.sort = Sort.valueOf(sort).name();
- } catch (IllegalArgumentException e){
- throw new IllegalArgumentException("Sort should contain only : " + Arrays.toString(Sort.values()), e);
- }
- }
+ public Builder sort(@Nullable Sort sort) {
+ this.sort = sort;
return this;
}
/**
* @since 3.6
*/
- public Rule setCreatedAt(Date created_at) {
- this.createdAt = created_at;
+ public Rule setCreatedAt(Date d) {
+ this.createdAt = d;
return this;
}
.assigned(true)
.createdAfter(new Date())
.createdBefore(new Date())
- .sort("assignee")
+ .sort(IssueQuery.Sort.ASSIGNEE)
.pageSize(10)
.pageIndex(2)
.build();
assertThat(query.rules()).containsOnly(RuleKey.of("squid", "AvoidCycle"));
assertThat(query.createdAfter()).isNotNull();
assertThat(query.createdBefore()).isNotNull();
- assertThat(query.sort()).isEqualTo("assignee");
+ assertThat(query.sort()).isEqualTo(IssueQuery.Sort.ASSIGNEE);
assertThat(query.pageSize()).isEqualTo(10);
assertThat(query.pageIndex()).isEqualTo(2);
}
}
@Test
- public void should_validate_sort() throws Exception {
- try {
- IssueQuery.builder()
- .sort("INVALID SORT")
- .build();
- fail();
- } catch (Exception e) {
- assertThat(e).hasMessage("Sort should contain only : [created, updated, closed, assignee]").isInstanceOf(IllegalArgumentException.class);
- }
+ public void should_accept_null_sort() throws Exception {
+ IssueQuery query = IssueQuery.builder().sort(null).build();
+ assertThat(query.sort()).isNull();
}
}
private final ResourceDao resourceDao;
private final ActionPlanIssueDao actionPlanIssueDao;
- public ServerIssueFinder(MyBatis myBatis, IssueDao issueDao, AuthorizationDao authorizationDao, DefaultRuleFinder ruleFinder, ResourceDao resourceDao, ActionPlanIssueDao actionPlanIssueDao) {
+ public ServerIssueFinder(MyBatis myBatis, IssueDao issueDao, AuthorizationDao authorizationDao,
+ DefaultRuleFinder ruleFinder, ResourceDao resourceDao,
+ ActionPlanIssueDao actionPlanIssueDao) {
this.myBatis = myBatis;
this.issueDao = issueDao;
this.authorizationDao = authorizationDao;
import org.sonar.api.issue.IssueFinder;
import org.sonar.api.issue.IssueQuery;
import org.sonar.api.issue.WebIssues;
-import org.sonar.api.issue.WebIssues;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.utils.DateUtils;
import org.sonar.api.web.UserRole;
import org.sonar.server.platform.UserSession;
import javax.annotation.Nullable;
-
import java.util.Collection;
import java.util.Date;
import java.util.List;
builder.createdBefore(toDate(props.get("createdBefore")));
builder.pageSize(toInteger(props.get("pageSize")));
builder.pageIndex(toInteger(props.get("pageIndex")));
+ String sort = (String) props.get("sort");
+ if (sort != null) {
+ builder.sort(IssueQuery.Sort.valueOf(sort));
+ }
return builder.build();
}
public class UserSession {
- private static final ThreadLocal<UserSession> threadLocal = new ThreadLocal<UserSession>();
+ private static final ThreadLocal<UserSession> THREAD_LOCAL = new ThreadLocal<UserSession>();
private static final UserSession DEFAULT_ANONYMOUS = new UserSession(null, null, Locale.ENGLISH);
private final Integer userId;
* @return never null
*/
public static UserSession get() {
- return Objects.firstNonNull(threadLocal.get(), DEFAULT_ANONYMOUS);
+ return Objects.firstNonNull(THREAD_LOCAL.get(), DEFAULT_ANONYMOUS);
}
public static void set(@Nullable UserSession session) {
- threadLocal.set(session);
+ THREAD_LOCAL.set(session);
}
public static void setSession(@Nullable Integer userId, @Nullable String login, @Nullable String localeRubyKey) {
}
public static void remove() {
- threadLocal.remove();
+ THREAD_LOCAL.remove();
}
static boolean hasSession() {
- return threadLocal.get() != null;
+ return THREAD_LOCAL.get() != null;
}
}