diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2015-11-13 10:42:27 +0100 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2015-11-17 13:41:03 +0100 |
commit | 563fbccfafb8d7225b7fe3f98f87f415c805217a (patch) | |
tree | 225d90c98bf83503208b6dd4419cdd69bc2ae372 /server/sonar-server | |
parent | c40eb47f54f7cfe94bd5cf6a9856a731a1b4dfc6 (diff) | |
download | sonarqube-563fbccfafb8d7225b7fe3f98f87f415c805217a.tar.gz sonarqube-563fbccfafb8d7225b7fe3f98f87f415c805217a.zip |
SONAR-6947 api/permissions/search_templates use SearchTemplatesWsRequest
Diffstat (limited to 'server/sonar-server')
2 files changed, 27 insertions, 19 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/SearchTemplatesAction.java b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/SearchTemplatesAction.java index 81ac05f93a0..37d1eeef3da 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/SearchTemplatesAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/SearchTemplatesAction.java @@ -24,16 +24,19 @@ import org.sonar.api.i18n.I18n; 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.Param; import org.sonar.core.permission.ProjectPermissions; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.permission.PermissionTemplateDto; import org.sonar.server.permission.ws.PermissionsWsAction; import org.sonar.server.user.UserSession; +import org.sonarqube.ws.WsPermissions; import org.sonarqube.ws.WsPermissions.Permission; import org.sonarqube.ws.WsPermissions.PermissionTemplate; -import org.sonarqube.ws.WsPermissions.WsSearchTemplatesResponse; -import org.sonarqube.ws.WsPermissions.WsSearchTemplatesResponse.TemplateIdQualifier; +import org.sonarqube.ws.WsPermissions.SearchTemplatesWsResponse; +import org.sonarqube.ws.WsPermissions.SearchTemplatesWsResponse.TemplateIdQualifier; +import org.sonarqube.ws.client.permission.SearchTemplatesWsRequest; import static org.sonar.api.utils.DateUtils.formatDateTime; import static org.sonar.server.permission.PermissionPrivilegeChecker.checkGlobalAdminUser; @@ -70,18 +73,26 @@ public class SearchTemplatesAction implements PermissionsWsAction { public void handle(Request wsRequest, Response wsResponse) throws Exception { checkGlobalAdminUser(userSession); + SearchTemplatesWsResponse searchTemplatesWsResponse = doHandle(toSearchTemplatesWsRequest(wsRequest)); + writeProtobuf(searchTemplatesWsResponse, wsRequest, wsResponse); + } + + private SearchTemplatesWsResponse doHandle(SearchTemplatesWsRequest wsRequest) { DbSession dbSession = dbClient.openSession(false); try { SearchTemplatesData data = dataLoader.load(wsRequest); - WsSearchTemplatesResponse response = buildResponse(data); - writeProtobuf(response, wsRequest, wsResponse); + return buildResponse(data); } finally { dbClient.closeSession(dbSession); } } - private WsSearchTemplatesResponse buildResponse(SearchTemplatesData data) { - WsSearchTemplatesResponse.Builder response = WsSearchTemplatesResponse.newBuilder(); + private static SearchTemplatesWsRequest toSearchTemplatesWsRequest(Request request) { + return new SearchTemplatesWsRequest().setQuery(request.param(Param.TEXT_QUERY)); + } + + private WsPermissions.SearchTemplatesWsResponse buildResponse(SearchTemplatesData data) { + SearchTemplatesWsResponse.Builder response = SearchTemplatesWsResponse.newBuilder(); buildTemplatesResponse(response, data); buildDefaultTemplatesResponse(response, data); @@ -90,7 +101,7 @@ public class SearchTemplatesAction implements PermissionsWsAction { return response.build(); } - private static void buildDefaultTemplatesResponse(WsSearchTemplatesResponse.Builder response, SearchTemplatesData data) { + private static void buildDefaultTemplatesResponse(SearchTemplatesWsResponse.Builder response, SearchTemplatesData data) { TemplateIdQualifier.Builder templateUuidQualifierBuilder = TemplateIdQualifier.newBuilder(); for (DefaultPermissionTemplateFinder.TemplateUuidQualifier templateUuidQualifier : data.defaultTempltes()) { response.addDefaultTemplates(templateUuidQualifierBuilder @@ -100,7 +111,7 @@ public class SearchTemplatesAction implements PermissionsWsAction { } } - private static void buildTemplatesResponse(WsSearchTemplatesResponse.Builder response, SearchTemplatesData data) { + private static void buildTemplatesResponse(WsPermissions.SearchTemplatesWsResponse.Builder response, SearchTemplatesData data) { Permission.Builder permissionResponse = Permission.newBuilder(); PermissionTemplate.Builder templateBuilder = PermissionTemplate.newBuilder(); @@ -129,7 +140,7 @@ public class SearchTemplatesAction implements PermissionsWsAction { } } - private void buildPermissionsResponse(WsSearchTemplatesResponse.Builder response) { + private void buildPermissionsResponse(SearchTemplatesWsResponse.Builder response) { Permission.Builder permissionResponse = Permission.newBuilder(); for (String permissionKey : ProjectPermissions.ALL) { response.addPermissions( @@ -137,8 +148,7 @@ public class SearchTemplatesAction implements PermissionsWsAction { .clear() .setKey(permissionKey) .setName(i18nName(permissionKey)) - .setDescription(i18nDescriptionMessage(permissionKey)) - ); + .setDescription(i18nDescriptionMessage(permissionKey))); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/SearchTemplatesDataLoader.java b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/SearchTemplatesDataLoader.java index dd561143f2c..15c8543f7c0 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/SearchTemplatesDataLoader.java +++ b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/SearchTemplatesDataLoader.java @@ -28,14 +28,13 @@ import java.util.List; import javax.annotation.Nonnull; import org.apache.ibatis.session.ResultContext; import org.apache.ibatis.session.ResultHandler; -import org.sonar.api.server.ws.Request; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.permission.CountByTemplateAndPermissionDto; import org.sonar.db.permission.PermissionTemplateDto; import org.sonar.server.permission.ws.template.DefaultPermissionTemplateFinder.TemplateUuidQualifier; +import org.sonarqube.ws.client.permission.SearchTemplatesWsRequest; -import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY; import static org.sonar.server.permission.ws.template.SearchTemplatesData.newBuilder; public class SearchTemplatesDataLoader { @@ -47,11 +46,11 @@ public class SearchTemplatesDataLoader { this.defaultPermissionTemplateFinder = defaultPermissionTemplateFinder; } - public SearchTemplatesData load(Request wsRequest) { + public SearchTemplatesData load(SearchTemplatesWsRequest request) { DbSession dbSession = dbClient.openSession(false); try { SearchTemplatesData.Builder data = newBuilder(); - List<PermissionTemplateDto> templates = searchTemplates(dbSession, wsRequest); + List<PermissionTemplateDto> templates = searchTemplates(dbSession, request); List<Long> templateIds = Lists.transform(templates, TemplateToIdFunction.INSTANCE); List<TemplateUuidQualifier> defaultTemplates = defaultPermissionTemplateFinder.getDefaultTemplatesByQualifier(); @@ -66,11 +65,10 @@ public class SearchTemplatesDataLoader { } } - private List<PermissionTemplateDto> searchTemplates(DbSession dbSession, Request wsRequest) { - String nameMatch = wsRequest.param(TEXT_QUERY); + private List<PermissionTemplateDto> searchTemplates(DbSession dbSession, SearchTemplatesWsRequest request) { + String nameMatch = request.getQuery(); - return nameMatch == null ? - dbClient.permissionTemplateDao().selectAll(dbSession) + return nameMatch == null ? dbClient.permissionTemplateDao().selectAll(dbSession) : dbClient.permissionTemplateDao().selectAll(dbSession, nameMatch); } |