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 onComponentOnly(boolean onComponentOnly) {
070    params.put("onComponentOnly", onComponentOnly);
071    return this;
072  }
073
074  public IssueQuery rules(String... s) {
075    return addParam("rules", s);
076  }
077
078  public IssueQuery actionPlans(String... s) {
079    return addParam("actionPlans", s);
080  }
081
082  public IssueQuery reporters(String... s) {
083    return addParam("reporters", s);
084  }
085
086  public IssueQuery assignees(String... s) {
087    return addParam("assignees", s);
088  }
089  public IssueQuery languages(String... s) {
090    return addParam("languages", s);
091  }
092
093  public IssueQuery assigned(Boolean assigned) {
094    params.put("assigned", assigned);
095    return this;
096  }
097
098  public IssueQuery planned(Boolean planned) {
099    params.put("planned", planned);
100    return this;
101  }
102
103  public IssueQuery resolved(Boolean resolved) {
104    params.put("resolved", resolved);
105    return this;
106  }
107
108  /**
109   * @since 4.2
110   */
111  public IssueQuery hideRules(Boolean hideRules) {
112    params.put("hideRules", hideRules);
113    return this;
114  }
115
116  /**
117   * Require second precision.
118   * @since 3.7
119   */
120  public IssueQuery createdAt(Date d) {
121    params.put("createdAt", EncodingUtils.toQueryParam(d, true));
122    return this;
123  }
124
125  public IssueQuery createdAfter(Date d) {
126    params.put("createdAfter", EncodingUtils.toQueryParam(d, true));
127    return this;
128  }
129
130  public IssueQuery createdBefore(Date d) {
131    params.put("createdBefore", EncodingUtils.toQueryParam(d, true));
132    return this;
133  }
134
135  public IssueQuery sort(String sort) {
136    params.put("sort", sort);
137    return this;
138  }
139
140  public IssueQuery asc(boolean asc) {
141    params.put("asc", asc);
142    return this;
143  }
144
145  public IssueQuery pageSize(int pageSize) {
146    params.put("pageSize", pageSize);
147    return this;
148  }
149
150  public IssueQuery pageIndex(int pageIndex) {
151    params.put("pageIndex", pageIndex);
152    return this;
153  }
154
155  private IssueQuery addParam(String key, String[] values) {
156    if (values != null) {
157      params.put(key, EncodingUtils.toQueryParam(values));
158    }
159    return this;
160  }
161
162}