You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RulesService.java 9.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2021 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonarqube.ws.client.rules;
  21. import java.util.stream.Collectors;
  22. import javax.annotation.Generated;
  23. import org.sonarqube.ws.MediaTypes;
  24. import org.sonarqube.ws.Rules.CreateResponse;
  25. import org.sonarqube.ws.Rules.ListResponse;
  26. import org.sonarqube.ws.Rules.SearchResponse;
  27. import org.sonarqube.ws.Rules.ShowResponse;
  28. import org.sonarqube.ws.Rules.UpdateResponse;
  29. import org.sonarqube.ws.client.BaseService;
  30. import org.sonarqube.ws.client.GetRequest;
  31. import org.sonarqube.ws.client.PostRequest;
  32. import org.sonarqube.ws.client.WsConnector;
  33. /**
  34. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/rules">Further information about this web service online</a>
  35. */
  36. @Generated("sonar-ws-generator")
  37. public class RulesService extends BaseService {
  38. public RulesService(WsConnector wsConnector) {
  39. super(wsConnector, "api/rules");
  40. }
  41. /**
  42. *
  43. * This is part of the internal API.
  44. * This is a GET request.
  45. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/rules/app">Further information about this action online (including a response example)</a>
  46. * @since 4.5
  47. */
  48. public String app(AppRequest request) {
  49. return call(
  50. new GetRequest(path("app"))
  51. .setMediaType(MediaTypes.JSON)).content();
  52. }
  53. /**
  54. *
  55. * This is part of the internal API.
  56. * This is a POST request.
  57. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/rules/create">Further information about this action online (including a response example)</a>
  58. * @since 4.4
  59. */
  60. public void create(CreateRequest request) {
  61. call(
  62. new PostRequest(path("create"))
  63. .setParam("custom_key", request.getCustomKey())
  64. .setParam("markdown_description", request.getMarkdownDescription())
  65. .setParam("name", request.getName())
  66. .setParam("params", request.getParams() == null ? null : request.getParams().stream().collect(Collectors.joining(",")))
  67. .setParam("prevent_reactivation", request.getPreventReactivation())
  68. .setParam("severity", request.getSeverity())
  69. .setParam("status", request.getStatus())
  70. .setParam("template_key", request.getTemplateKey())
  71. .setParam("type", request.getType()),
  72. CreateResponse.parser());
  73. }
  74. /**
  75. *
  76. * This is part of the internal API.
  77. * This is a POST request.
  78. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/rules/delete">Further information about this action online (including a response example)</a>
  79. * @since 4.4
  80. */
  81. public void delete(DeleteRequest request) {
  82. call(
  83. new PostRequest(path("delete"))
  84. .setParam("key", request.getKey())
  85. .setMediaType(MediaTypes.JSON)).content();
  86. }
  87. /**
  88. *
  89. * This is part of the internal API.
  90. * This is a GET request.
  91. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/rules/list">Further information about this action online (including a response example)</a>
  92. * @since 5.2
  93. */
  94. public ListResponse list() {
  95. return call(
  96. new GetRequest(path("list")),
  97. ListResponse.parser());
  98. }
  99. /**
  100. *
  101. * This is part of the internal API.
  102. * This is a GET request.
  103. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/rules/repositories">Further information about this action online (including a response example)</a>
  104. * @since 4.5
  105. */
  106. public String repositories(RepositoriesRequest request) {
  107. return call(
  108. new GetRequest(path("repositories"))
  109. .setParam("language", request.getLanguage())
  110. .setParam("q", request.getQ())
  111. .setMediaType(MediaTypes.JSON)).content();
  112. }
  113. /**
  114. *
  115. * This is part of the internal API.
  116. * This is a GET request.
  117. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/rules/search">Further information about this action online (including a response example)</a>
  118. * @since 4.4
  119. */
  120. public SearchResponse search(SearchRequest request) {
  121. return call(
  122. new GetRequest(path("search"))
  123. .setParam("activation", request.getActivation())
  124. .setParam("active_severities", request.getActiveSeverities() == null ? null : request.getActiveSeverities().stream().collect(Collectors.joining(",")))
  125. .setParam("asc", request.getAsc())
  126. .setParam("available_since", request.getAvailableSince())
  127. .setParam("compareToProfile", request.getCompareToProfile())
  128. .setParam("f", request.getF() == null ? null : request.getF().stream().collect(Collectors.joining(",")))
  129. .setParam("facets", request.getFacets() == null ? null : request.getFacets().stream().collect(Collectors.joining(",")))
  130. .setParam("inheritance", request.getInheritance() == null ? null : request.getInheritance().stream().collect(Collectors.joining(",")))
  131. .setParam("is_template", request.getIsTemplate())
  132. .setParam("include_external", request.getIncludeExternal())
  133. .setParam("languages", request.getLanguages() == null ? null : request.getLanguages().stream().collect(Collectors.joining(",")))
  134. .setParam("p", request.getP())
  135. .setParam("ps", request.getPs())
  136. .setParam("q", request.getQ())
  137. .setParam("qprofile", request.getQprofile())
  138. .setParam("repositories", request.getRepositories() == null ? null : request.getRepositories().stream().collect(Collectors.joining(",")))
  139. .setParam("rule_key", request.getRuleKey())
  140. .setParam("s", request.getS())
  141. .setParam("severities", request.getSeverities() == null ? null : request.getSeverities().stream().collect(Collectors.joining(",")))
  142. .setParam("statuses", request.getStatuses() == null ? null : request.getStatuses().stream().collect(Collectors.joining(",")))
  143. .setParam("cwe", request.getCwe() == null ? null : request.getCwe().stream().collect(Collectors.joining(",")))
  144. .setParam("owaspTop10", request.getOwaspTop10() == null ? null : request.getOwaspTop10().stream().collect(Collectors.joining(",")))
  145. .setParam("sansTop25", request.getSansTop25() == null ? null : request.getSansTop25().stream().collect(Collectors.joining(",")))
  146. .setParam("sonarsourceSecurity", request.getSonarsourceSecurity() == null ? null : request.getSonarsourceSecurity().stream().collect(Collectors.joining(",")))
  147. .setParam("tags", request.getTags() == null ? null : request.getTags().stream().collect(Collectors.joining(",")))
  148. .setParam("template_key", request.getTemplateKey())
  149. .setParam("types", request.getTypes() == null ? null : request.getTypes().stream().collect(Collectors.joining(","))),
  150. SearchResponse.parser());
  151. }
  152. /**
  153. *
  154. * This is part of the internal API.
  155. * This is a GET request.
  156. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/rules/show">Further information about this action online (including a response example)</a>
  157. * @since 4.2
  158. */
  159. public ShowResponse show(ShowRequest request) {
  160. return call(
  161. new GetRequest(path("show"))
  162. .setParam("actives", request.getActives())
  163. .setParam("key", request.getKey()),
  164. ShowResponse.parser());
  165. }
  166. /**
  167. *
  168. * This is part of the internal API.
  169. * This is a GET request.
  170. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/rules/tags">Further information about this action online (including a response example)</a>
  171. * @since 4.4
  172. */
  173. public String tags(TagsRequest request) {
  174. return call(
  175. new GetRequest(path("tags"))
  176. .setParam("ps", request.getPs())
  177. .setParam("q", request.getQ())
  178. .setMediaType(MediaTypes.JSON)).content();
  179. }
  180. /**
  181. *
  182. * This is part of the internal API.
  183. * This is a POST request.
  184. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/rules/update">Further information about this action online (including a response example)</a>
  185. * @since 4.4
  186. */
  187. public void update(UpdateRequest request) {
  188. call(
  189. new PostRequest(path("update"))
  190. .setParam("key", request.getKey())
  191. .setParam("markdown_description", request.getMarkdownDescription())
  192. .setParam("markdown_note", request.getMarkdownNote())
  193. .setParam("name", request.getName())
  194. .setParam("params", request.getParams() == null ? null : request.getParams().stream().collect(Collectors.joining(",")))
  195. .setParam("remediation_fn_base_effort", request.getRemediationFnBaseEffort())
  196. .setParam("remediation_fn_type", request.getRemediationFnType())
  197. .setParam("remediation_fy_gap_multiplier", request.getRemediationFyGapMultiplier())
  198. .setParam("severity", request.getSeverity())
  199. .setParam("status", request.getStatus())
  200. .setParam("tags", request.getTags() == null ? null : request.getTags().stream().collect(Collectors.joining(","))),
  201. UpdateResponse.parser());
  202. }
  203. }