]> source.dussan.org Git - sonarqube.git/commitdiff
refactor WS using 'f' and 'q' parameters with WebService.Param fields 298/head
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Fri, 8 May 2015 16:17:10 +0000 (18:17 +0200)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Mon, 11 May 2015 15:33:28 +0000 (17:33 +0200)
server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchAction.java
server/sonar-server/src/main/java/org/sonar/server/issue/ws/TagsAction.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileSearchAction.java
server/sonar-server/src/main/java/org/sonar/server/user/ws/GroupsAction.java

index 50599c6d0582916a3bc4a1d339daa0cc1bb3f13c..482390c8344ddaadb1bc04f122dda6af51417320 100644 (file)
@@ -25,6 +25,7 @@ import org.sonar.api.server.ws.Request;
 import org.sonar.api.server.ws.RequestHandler;
 import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService;
+import org.sonar.api.server.ws.WebService.Param;
 import org.sonar.api.utils.text.JsonWriter;
 import org.sonar.api.web.UserRole;
 import org.sonar.core.component.ComponentDto;
@@ -47,7 +48,6 @@ public class SearchAction implements RequestHandler {
   private static final short MINIMUM_SEARCH_CHARACTERS = 2;
 
   private static final String PARAM_COMPONENT_UUID = "componentUuid";
-  private static final String PARAM_QUERY = "q";
 
   private final DbClient dbClient;
 
@@ -69,7 +69,7 @@ public class SearchAction implements RequestHandler {
       .setExampleValue("d6d9e1e5-5e13-44fa-ab82-3ec29efa8935");
 
     action
-      .createParam(PARAM_QUERY)
+      .createParam(Param.TEXT_QUERY)
       .setRequired(true)
       .setDescription("UTF-8 search query")
       .setExampleValue("sonar");
@@ -79,7 +79,7 @@ public class SearchAction implements RequestHandler {
 
   @Override
   public void handle(Request request, Response response) {
-    String query = request.mandatoryParam(PARAM_QUERY);
+    String query = request.mandatoryParam(Param.TEXT_QUERY);
     if (query.length() < MINIMUM_SEARCH_CHARACTERS) {
       throw new IllegalArgumentException(String.format("Minimum search is %s characters", MINIMUM_SEARCH_CHARACTERS));
     }
index c3da60898a4169276f5fbe6464b6a2a9227705d9..d4a862d16784e41e0dde741011a1cdbe6fd605c5 100644 (file)
@@ -24,6 +24,7 @@ import org.sonar.api.server.ws.Request;
 import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.api.server.ws.WebService.NewAction;
+import org.sonar.api.server.ws.WebService.Param;
 import org.sonar.api.utils.text.JsonWriter;
 import org.sonar.server.issue.IssueService;
 
@@ -46,7 +47,7 @@ public class TagsAction implements BaseIssuesWsAction {
       .setSince("5.1")
       .setDescription("List tags matching a given query")
       .setResponseExample(Resources.getResource(getClass(), "example-tags.json"));
-    action.createParam("q")
+    action.createParam(Param.TEXT_QUERY)
       .setDescription("A pattern to match tags against")
       .setExampleValue("misra");
     action.createParam("ps")
@@ -57,7 +58,7 @@ public class TagsAction implements BaseIssuesWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    String query = request.param("q");
+    String query = request.param(Param.TEXT_QUERY);
     int pageSize = request.mandatoryParamAsInt("ps");
     JsonWriter json = response.newJsonWriter().beginObject().name("tags").beginArray();
     for (String tag: service.listTags(query, pageSize)) {
index 8742cd7bb3bc7c9b809b4c67f677abaf225ff80a..d8149bf8849e42a841e8de378d0edd3cde9b11c0 100644 (file)
@@ -27,6 +27,7 @@ import org.sonar.api.server.ws.Request;
 import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.api.server.ws.WebService.NewAction;
+import org.sonar.api.server.ws.WebService.Param;
 import org.sonar.api.utils.text.JsonWriter;
 import org.sonar.core.qualityprofile.db.QualityProfileDao;
 import org.sonar.core.util.NonNullInputFunction;
@@ -61,8 +62,6 @@ public class QProfileSearchAction implements BaseQProfileWsAction {
     FIELD_PROJECT_COUNT);
 
   private static final String PARAM_LANGUAGE = FIELD_LANGUAGE;
-  private static final String PARAM_FIELDS = "f";
-
 
   private final Languages languages;
 
@@ -92,7 +91,7 @@ public class QProfileSearchAction implements BaseQProfileWsAction {
       .setExampleValue("js")
       .setPossibleValues(LanguageParamUtils.getLanguageKeys(languages));
 
-    search.createParam(PARAM_FIELDS)
+    search.createParam(Param.FIELDS)
       .setDescription("Use to restrict returned fields.")
       .setExampleValue("key,language")
       .setPossibleValues(ALL_FIELDS);
@@ -100,7 +99,7 @@ public class QProfileSearchAction implements BaseQProfileWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    List<String> fields = request.paramAsStrings(PARAM_FIELDS);
+    List<String> fields = request.paramAsStrings(Param.FIELDS);
 
     String language = request.param(PARAM_LANGUAGE);
 
@@ -136,7 +135,6 @@ public class QProfileSearchAction implements BaseQProfileWsAction {
     Map<String, Long> activeRuleCountByKey = profileLoader.countAllActiveRules();
     Map<String, Long> projectCountByKey = qualityProfileDao.countProjectsByProfileKey();
 
-
     json.name("profiles")
       .beginArray();
     for (QProfile profile : profiles) {
index f493c2f4eb0651aeec87d164ce1591f32f705917..b25a72f39a384827010fef4d3334713b45d79e74 100644 (file)
@@ -40,7 +40,6 @@ public class GroupsAction implements BaseUsersWsAction {
 
   private static final String PARAM_LOGIN = "login";
   private static final String PARAM_SELECTED = "selected";
-  private static final String PARAM_QUERY = "q";
 
   private static final String SELECTION_ALL = "all";
   private static final String SELECTION_SELECTED = "selected";
@@ -70,7 +69,7 @@ public class GroupsAction implements BaseUsersWsAction {
       .setPossibleValues(SELECTION_SELECTED, SELECTION_DESELECTED, SELECTION_ALL)
       .setDefaultValue(SELECTION_ALL);
 
-    action.createParam(PARAM_QUERY)
+    action.createParam(Param.TEXT_QUERY)
       .setDescription("If specified, only show groups whose name contains the query.")
       .setExampleValue("user");
 
@@ -82,7 +81,7 @@ public class GroupsAction implements BaseUsersWsAction {
     String login = request.mandatoryParam(PARAM_LOGIN);
     int pageSize = request.mandatoryParamAsInt(Param.PAGE_SIZE);
     int page = request.mandatoryParamAsInt(Param.PAGE);
-    String queryString = request.param(PARAM_QUERY);
+    String queryString = request.param(Param.TEXT_QUERY);
     String selected = request.param(PARAM_SELECTED);
 
     GroupMembershipQuery query = GroupMembershipQuery.builder()