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   * @since 4.2
106   */
107  public IssueQuery hideRules(Boolean hideRules) {
108    params.put("hideRules", hideRules);
109    return this;
110  }
111
112  /**
113   * Require second precision.
114   * @since 3.7
115   */
116  public IssueQuery createdAt(Date d) {
117    params.put("createdAt", EncodingUtils.toQueryParam(d, true));
118    return this;
119  }
120
121  public IssueQuery createdAfter(Date d) {
122    params.put("createdAfter", EncodingUtils.toQueryParam(d, true));
123    return this;
124  }
125
126  public IssueQuery createdBefore(Date d) {
127    params.put("createdBefore", EncodingUtils.toQueryParam(d, true));
128    return this;
129  }
130
131  public IssueQuery sort(String sort) {
132    params.put("sort", sort);
133    return this;
134  }
135
136  public IssueQuery asc(boolean asc) {
137    params.put("asc", asc);
138    return this;
139  }
140
141  public IssueQuery pageSize(int pageSize) {
142    params.put("pageSize", pageSize);
143    return this;
144  }
145
146  public IssueQuery pageIndex(int pageIndex) {
147    params.put("pageIndex", pageIndex);
148    return this;
149  }
150
151  private IssueQuery addParam(String key, String[] values) {
152    if (values != null) {
153      params.put(key, EncodingUtils.toQueryParam(values));
154    }
155    return this;
156  }
157
158}