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.services;
021
022/**
023 * @deprecated in 3.6. Replaced by issues.
024 */
025@Deprecated
026public class ViolationQuery extends Query<Violation> {
027
028  public static final String BASE_URL = "/api/violations";
029
030  private String resourceKey;
031  private int depth = 0;
032  private String[] qualifiers;
033  private String[] ruleKeys;
034  private String[] severities;
035  private Integer limit;
036
037  public ViolationQuery(String resourceKey) {
038    this.resourceKey = resourceKey;
039  }
040
041  public String[] getQualifiers() {
042    return qualifiers;
043  }
044
045  public ViolationQuery setQualifiers(String... qualifiers) {
046    this.qualifiers = qualifiers;
047    return this;
048  }
049
050  public String[] getRuleKeys() {
051    return ruleKeys;
052  }
053
054  public ViolationQuery setRuleKeys(String... ruleKeys) {
055    this.ruleKeys = ruleKeys;
056    return this;
057  }
058
059  /**
060   * @since 2.5
061   */
062  public String[] getSeverities() {
063    return severities;
064  }
065
066  /**
067   * @since 2.5
068   */
069  public ViolationQuery setSeverities(String... severities) {
070    this.severities = severities;
071    return this;
072  }
073
074  /**
075   * @deprecated since 2.5 use {@link #getSeverities()} instead. See http://jira.codehaus.org/browse/SONAR-1829
076   */
077  @Deprecated
078  public String[] getPriorities() {
079    return severities;
080  }
081
082  /**
083   * @deprecated since 2.5 use {@link #setSeverities(String...)} instead. See http://jira.codehaus.org/browse/SONAR-1829
084   */
085  @Deprecated
086  public ViolationQuery setPriorities(String... priorities) {
087    this.severities = priorities;
088    return this;
089  }
090
091  public int getDepth() {
092    return depth;
093  }
094
095  public ViolationQuery setDepth(int depth) {
096    this.depth = depth;
097    return this;
098  }
099
100  /**
101   * @since 2.5
102   */
103  public Integer getLimit() {
104    return limit;
105  }
106
107  /**
108   * @since 2.5
109   */
110  public ViolationQuery setLimit(Integer limit) {
111    this.limit = limit;
112    return this;
113  }
114
115  @Override
116  public String getUrl() {
117    StringBuilder url = new StringBuilder(BASE_URL);
118    url.append('?');
119    appendUrlParameter(url, "resource", resourceKey);
120    if (depth != 0) {
121      url.append("depth=").append(depth).append("&");
122    }
123    appendUrlParameter(url, "limit", limit);
124    appendUrlParameter(url, "qualifiers", qualifiers);
125    appendUrlParameter(url, "rules", ruleKeys);
126    appendUrlParameter(url, "priorities", severities);
127    return url.toString();
128  }
129
130  @Override
131  public Class<Violation> getModelClass() {
132    return Violation.class;
133  }
134
135  public static ViolationQuery createForResource(Resource resource) {
136    Integer id = resource.getId();
137    if (id == null) {
138      throw new IllegalArgumentException("id must be set");
139    }
140    return new ViolationQuery(id.toString());
141  }
142
143  public static ViolationQuery createForResource(String resourceIdOrKey) {
144    return new ViolationQuery(resourceIdOrKey);
145  }
146}