001 /* 002 * Sonar, open source software quality management tool. 003 * Copyright (C) 2009 SonarSource SA 004 * mailto:contact AT sonarsource DOT com 005 * 006 * Sonar 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 * Sonar 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 017 * License along with Sonar; if not, write to the Free Software 018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 019 */ 020 package org.sonar.wsclient.services; 021 022 /** 023 * @since 2.5 024 */ 025 public class RuleQuery extends Query<Rule> { 026 public static final String BASE_URL = "/api/rules"; 027 028 private String language; 029 private String[] repositories; 030 private String searchText; 031 private String profile; 032 private String[] severities; 033 private Boolean active; 034 035 public RuleQuery(String language) { 036 this.language = language; 037 } 038 039 public RuleQuery setLanguage(String language) { 040 this.language = language; 041 return this; 042 } 043 044 public String getLanguage() { 045 return language; 046 } 047 048 public RuleQuery setRepositories(String... s) { 049 this.repositories = s; 050 return this; 051 } 052 053 public String[] getRepositories() { 054 return repositories; 055 } 056 057 public RuleQuery setSearchText(String searchText) { 058 this.searchText = searchText; 059 return this; 060 } 061 062 public String getSearchText() { 063 return searchText; 064 } 065 066 public RuleQuery setProfile(String profile) { 067 this.profile = profile; 068 return this; 069 } 070 071 public String getProfile() { 072 return profile; 073 } 074 075 public RuleQuery setSeverities(String... severities) { 076 this.severities = severities; 077 return this; 078 } 079 080 public String[] getSeverities() { 081 return severities; 082 } 083 084 public RuleQuery setActive(Boolean active) { 085 this.active = active; 086 return this; 087 } 088 089 public Boolean getStatus() { 090 return active; 091 } 092 093 @Override 094 public String getUrl() { 095 StringBuilder url = new StringBuilder(BASE_URL); 096 url.append('?'); 097 appendUrlParameter(url, "language", language); 098 appendUrlParameter(url, "plugins", repositories); 099 appendUrlParameter(url, "searchtext", searchText); 100 appendUrlParameter(url, "profile", profile); 101 appendUrlParameter(url, "priorities", severities); 102 if (active != null) { 103 appendUrlParameter(url, "status", active ? "ACTIVE" : "INACTIVE"); 104 } 105 return url.toString(); 106 } 107 108 @Override 109 public Class<Rule> getModelClass() { 110 return Rule.class; 111 } 112 113 }