001/*
002 * SonarQube, open source software quality management tool.
003 * Copyright (C) 2008-2014 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  public IssueQuery languages(String... s) {
089    return addParam("languages", s);
090  }
091
092  public IssueQuery assigned(Boolean assigned) {
093    params.put("assigned", assigned);
094    return this;
095  }
096
097  public IssueQuery planned(Boolean planned) {
098    params.put("planned", planned);
099    return this;
100  }
101
102  public IssueQuery resolved(Boolean resolved) {
103    params.put("resolved", resolved);
104    return this;
105  }
106
107  /**
108   * @since 4.2
109   */
110  public IssueQuery hideRules(Boolean hideRules) {
111    params.put("hideRules", hideRules);
112    return this;
113  }
114
115  /**
116   * Require second precision.
117   * @since 3.7
118   */
119  public IssueQuery createdAt(Date d) {
120    params.put("createdAt", EncodingUtils.toQueryParam(d, true));
121    return this;
122  }
123
124  public IssueQuery createdAfter(Date d) {
125    params.put("createdAfter", EncodingUtils.toQueryParam(d, true));
126    return this;
127  }
128
129  public IssueQuery createdBefore(Date d) {
130    params.put("createdBefore", EncodingUtils.toQueryParam(d, true));
131    return this;
132  }
133
134  public IssueQuery sort(String sort) {
135    params.put("sort", sort);
136    return this;
137  }
138
139  public IssueQuery asc(boolean asc) {
140    params.put("asc", asc);
141    return this;
142  }
143
144  public IssueQuery pageSize(int pageSize) {
145    params.put("pageSize", pageSize);
146    return this;
147  }
148
149  public IssueQuery pageIndex(int pageIndex) {
150    params.put("pageIndex", pageIndex);
151    return this;
152  }
153
154  private IssueQuery addParam(String key, String[] values) {
155    if (values != null) {
156      params.put(key, EncodingUtils.toQueryParam(values));
157    }
158    return this;
159  }
160
161}