001/*
002 * SonarQube, open source software quality management tool.
003 * Copyright (C) 2008-2013 SonarSource
004 * mailto:contact AT sonarsource DOT com
005 *
006 * SonarQube is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (at your option) any later version.
010 *
011 * SonarQube is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public License
017 * along with this program; if not, write to the Free Software Foundation,
018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
019 */
020package org.sonar.wsclient.issue;
021
022import org.sonar.wsclient.internal.EncodingUtils;
023
024import java.util.Date;
025import java.util.HashMap;
026import java.util.Map;
027
028/**
029 * @since 3.6
030 */
031public class IssueQuery {
032
033  private final Map<String, Object> params = new HashMap<String, Object>();
034
035  private IssueQuery() {
036  }
037
038  public static IssueQuery create() {
039    return new IssueQuery();
040  }
041
042  /**
043   * URL query string, for internal use
044   */
045  public Map<String, Object> urlParams() {
046    return params;
047  }
048
049  public IssueQuery issues(String... keys) {
050    return addParam("issues", keys);
051  }
052
053  public IssueQuery severities(String... severities) {
054    return addParam("severities", severities);
055  }
056
057  public IssueQuery statuses(String... statuses) {
058    return addParam("statuses", statuses);
059  }
060
061  public IssueQuery resolutions(String... resolutions) {
062    return addParam("resolutions", resolutions);
063  }
064
065  public IssueQuery components(String... components) {
066    return addParam("components", components);
067  }
068
069  public IssueQuery componentRoots(String... componentRoots) {
070    return addParam("componentRoots", componentRoots);
071  }
072
073  public IssueQuery rules(String... s) {
074    return addParam("rules", s);
075  }
076
077  public IssueQuery actionPlans(String... s) {
078    return addParam("actionPlans", s);
079  }
080
081  public IssueQuery reporters(String... s) {
082    return addParam("reporters", s);
083  }
084
085  public IssueQuery assignees(String... s) {
086    return addParam("assignees", s);
087  }
088
089  public IssueQuery assigned(Boolean assigned) {
090    params.put("assigned", assigned);
091    return this;
092  }
093
094  public IssueQuery planned(Boolean planned) {
095    params.put("planned", planned);
096    return this;
097  }
098
099  public IssueQuery resolved(Boolean resolved) {
100    params.put("resolved", resolved);
101    return this;
102  }
103
104  /**
105   * Require second precision.
106   * @since 3.7
107   */
108  public IssueQuery createdAt(Date d) {
109    params.put("createdAt", EncodingUtils.toQueryParam(d, true));
110    return this;
111  }
112
113  public IssueQuery createdAfter(Date d) {
114    params.put("createdAfter", EncodingUtils.toQueryParam(d, true));
115    return this;
116  }
117
118  public IssueQuery createdBefore(Date d) {
119    params.put("createdBefore", EncodingUtils.toQueryParam(d, true));
120    return this;
121  }
122
123  public IssueQuery sort(String sort) {
124    params.put("sort", sort);
125    return this;
126  }
127
128  public IssueQuery asc(boolean asc) {
129    params.put("asc", asc);
130    return this;
131  }
132
133  public IssueQuery pageSize(int pageSize) {
134    params.put("pageSize", pageSize);
135    return this;
136  }
137
138  public IssueQuery pageIndex(int pageIndex) {
139    params.put("pageIndex", pageIndex);
140    return this;
141  }
142
143  private IssueQuery addParam(String key, String[] values) {
144    if (values != null) {
145      params.put(key, EncodingUtils.toQueryParam(values));
146    }
147    return this;
148  }
149
150}