1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2008-2011 SonarSource
* mailto:contact AT sonarsource DOT com
*
* Sonar is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* Sonar is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.wsclient.services;
public class ViolationQuery extends Query<Violation> {
public static final String BASE_URL = "/api/violations";
private String resourceKeyOrId;
private int depth = 0;
private String[] scopes;
private String[] qualifiers;
private String[] ruleKeys;
private String[] categories;
private String[] severities;
private Integer limit;
public ViolationQuery(String resourceKeyOrId) {
this.resourceKeyOrId = resourceKeyOrId;
}
public String[] getScopes() {
return scopes;
}
public ViolationQuery setScopes(String... scopes) {
this.scopes = scopes;
return this;
}
public String[] getQualifiers() {
return qualifiers;
}
public ViolationQuery setQualifiers(String... qualifiers) {
this.qualifiers = qualifiers;
return this;
}
public String[] getRuleKeys() {
return ruleKeys;
}
public ViolationQuery setRuleKeys(String... ruleKeys) {
this.ruleKeys = ruleKeys;
return this;
}
public String[] getCategories() {
return categories;
}
public ViolationQuery setCategories(String... categories) {
this.categories = categories;
return this;
}
/**
* @since 2.5
*/
public String[] getSeverities() {
return severities;
}
/**
* @since 2.5
*/
public ViolationQuery setSeverities(String... severities) {
this.severities = severities;
return this;
}
/**
* @deprecated since 2.5 use {@link #getSeverities()} instead. See http://jira.codehaus.org/browse/SONAR-1829
*/
@Deprecated
public String[] getPriorities() {
return severities;
}
/**
* @deprecated since 2.5 use {@link #setSeverities(String...)} instead. See http://jira.codehaus.org/browse/SONAR-1829
*/
@Deprecated
public ViolationQuery setPriorities(String... priorities) {
this.severities = priorities;
return this;
}
public int getDepth() {
return depth;
}
public ViolationQuery setDepth(int depth) {
this.depth = depth;
return this;
}
/**
* @since 2.5
*/
public Integer getLimit() {
return limit;
}
/**
* @since 2.5
*/
public ViolationQuery setLimit(Integer limit) {
this.limit = limit;
return this;
}
@Override
public String getUrl() {
StringBuilder url = new StringBuilder(BASE_URL);
url.append('?');
appendUrlParameter(url, "resource", resourceKeyOrId);
if (depth != 0) {
url.append("depth=").append(depth).append("&");
}
appendUrlParameter(url, "limit", limit);
appendUrlParameter(url, "scopes", scopes);
appendUrlParameter(url, "qualifiers", qualifiers);
appendUrlParameter(url, "rules", ruleKeys);
appendUrlParameter(url, "categories", categories);
appendUrlParameter(url, "priorities", severities);
return url.toString();
}
@Override
public Class<Violation> getModelClass() {
return Violation.class;
}
public static ViolationQuery createForResource(Resource resource) {
return new ViolationQuery(resource.getId().toString());
}
public static ViolationQuery createForResource(String resourceIdOrKey) {
return new ViolationQuery(resourceIdOrKey);
}
}
|