From 9f3a9dd2768ecf93c074a1d4020752be76a3a583 Mon Sep 17 00:00:00 2001 From: Teryk Bellahsene Date: Fri, 8 May 2015 18:17:10 +0200 Subject: [PATCH] refactor WS using 'f' and 'q' parameters with WebService.Param fields --- .../java/org/sonar/server/component/ws/SearchAction.java | 6 +++--- .../main/java/org/sonar/server/issue/ws/TagsAction.java | 5 +++-- .../server/qualityprofile/ws/QProfileSearchAction.java | 8 +++----- .../main/java/org/sonar/server/user/ws/GroupsAction.java | 5 ++--- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchAction.java index 50599c6d058..482390c8344 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchAction.java @@ -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)); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/TagsAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/TagsAction.java index c3da60898a4..d4a862d1678 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/TagsAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/TagsAction.java @@ -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)) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileSearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileSearchAction.java index 8742cd7bb3b..d8149bf8849 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileSearchAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileSearchAction.java @@ -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 fields = request.paramAsStrings(PARAM_FIELDS); + List fields = request.paramAsStrings(Param.FIELDS); String language = request.param(PARAM_LANGUAGE); @@ -136,7 +135,6 @@ public class QProfileSearchAction implements BaseQProfileWsAction { Map activeRuleCountByKey = profileLoader.countAllActiveRules(); Map projectCountByKey = qualityProfileDao.countProjectsByProfileKey(); - json.name("profiles") .beginArray(); for (QProfile profile : profiles) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/ws/GroupsAction.java b/server/sonar-server/src/main/java/org/sonar/server/user/ws/GroupsAction.java index f493c2f4eb0..b25a72f39a3 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/user/ws/GroupsAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/user/ws/GroupsAction.java @@ -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() -- 2.39.5