diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2019-08-12 11:16:43 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2019-08-14 20:21:14 +0200 |
commit | e9ae396829a95e449d2e02934fc0567e7f09f833 (patch) | |
tree | 35d6ef00a01d5914a29985b3708311db30b8535b | |
parent | 3a3948b47bcb86fe0bb7c427397303f54bfaa0ed (diff) | |
download | sonarqube-e9ae396829a95e449d2e02934fc0567e7f09f833.tar.gz sonarqube-e9ae396829a95e449d2e02934fc0567e7f09f833.zip |
move some WSUtils methods to NotFoundException and ServerException
99 files changed, 177 insertions, 185 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentFinder.java b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentFinder.java index 847d9d68653..86259eb3d01 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentFinder.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentFinder.java @@ -36,8 +36,8 @@ import org.sonar.server.exceptions.NotFoundException; import static com.google.common.base.Preconditions.checkArgument; import static java.lang.String.format; -import static org.sonar.server.ws.WsUtils.checkFoundWithOptional; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; public class ComponentFinder { private static final String MSG_COMPONENT_ID_OR_KEY_TEMPLATE = "Either '%s' or '%s' must be provided"; diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentService.java b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentService.java index 2b25909072c..bdef35a72ff 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentService.java @@ -42,7 +42,7 @@ import static java.util.Collections.singleton; import static java.util.Collections.singletonList; import static org.sonar.core.component.ComponentKeys.isValidProjectKey; import static org.sonar.db.component.ComponentKeyUpdaterDao.checkIsProjectOrModule; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; @ServerSide public class ComponentService { diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentUpdater.java b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentUpdater.java index 564dd64524a..f39283fef5f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentUpdater.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentUpdater.java @@ -42,7 +42,7 @@ import org.sonar.server.permission.PermissionTemplateService; import static java.util.Collections.singletonList; import static org.sonar.api.resources.Qualifiers.PROJECT; import static org.sonar.core.component.ComponentKeys.isValidProjectKey; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; public class ComponentUpdater { diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/AssignAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/AssignAction.java index 87105457585..884fad73b69 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/AssignAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/AssignAction.java @@ -34,7 +34,7 @@ import org.sonar.server.user.UserSession; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Strings.isNullOrEmpty; -import static org.sonar.server.ws.WsUtils.checkFound; +import static org.sonar.server.exceptions.NotFoundException.checkFound; @ServerSide public class AssignAction extends Action { diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/ApplyPermissionTemplateQuery.java b/server/sonar-server/src/main/java/org/sonar/server/permission/ApplyPermissionTemplateQuery.java index 42d163ab66c..f3b58fe6c02 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/permission/ApplyPermissionTemplateQuery.java +++ b/server/sonar-server/src/main/java/org/sonar/server/permission/ApplyPermissionTemplateQuery.java @@ -22,7 +22,7 @@ package org.sonar.server.permission; import java.util.List; import static org.apache.commons.lang.StringUtils.isNotBlank; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; public class ApplyPermissionTemplateQuery { diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/GroupPermissionChanger.java b/server/sonar-server/src/main/java/org/sonar/server/permission/GroupPermissionChanger.java index f285f7b0d25..5e6a0a48dd0 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/permission/GroupPermissionChanger.java +++ b/server/sonar-server/src/main/java/org/sonar/server/permission/GroupPermissionChanger.java @@ -30,7 +30,7 @@ import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN; import static org.sonar.server.permission.PermissionChange.Operation.ADD; import static org.sonar.server.permission.PermissionChange.Operation.REMOVE; import static org.sonar.server.permission.RequestValidator.validateNotAnyoneAndAdminPermission; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; public class GroupPermissionChanger { diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionChange.java b/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionChange.java index 8fe28ff7872..94ed74562d5 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionChange.java +++ b/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionChange.java @@ -26,7 +26,7 @@ import org.sonar.db.permission.OrganizationPermission; import static java.util.Objects.requireNonNull; import static org.sonar.core.util.stream.MoreCollectors.toList; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; public abstract class PermissionChange { diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/RequestValidator.java b/server/sonar-server/src/main/java/org/sonar/server/permission/RequestValidator.java index be763cce0e2..8fe5e6ba069 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/permission/RequestValidator.java +++ b/server/sonar-server/src/main/java/org/sonar/server/permission/RequestValidator.java @@ -29,11 +29,10 @@ import org.sonar.api.resources.ResourceType; import org.sonar.api.resources.ResourceTypes; import org.sonar.core.permission.GlobalPermissions; import org.sonar.server.exceptions.BadRequestException; -import org.sonar.server.ws.WsUtils; import static com.google.common.base.Strings.isNullOrEmpty; import static java.lang.String.format; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION; import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_KEY_PATTERN; import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_QUALIFIER; @@ -49,7 +48,7 @@ public class RequestValidator { } public String validateProjectPermission(String permission) { - WsUtils.checkRequest(permissionService.getAllProjectPermissions().contains(permission), + BadRequestException.checkRequest(permissionService.getAllProjectPermissions().contains(permission), String.format("The '%s' parameter for project permissions must be one of %s. '%s' was passed.", PARAM_PERMISSION, allProjectsPermissionsOnOneLine, permission)); return permission; diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/UserPermissionChanger.java b/server/sonar-server/src/main/java/org/sonar/server/permission/UserPermissionChanger.java index 62d4a15ff64..04239af9724 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/permission/UserPermissionChanger.java +++ b/server/sonar-server/src/main/java/org/sonar/server/permission/UserPermissionChanger.java @@ -29,7 +29,7 @@ import static org.sonar.api.web.UserRole.PUBLIC_PERMISSIONS; import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN; import static org.sonar.server.permission.PermissionChange.Operation.ADD; import static org.sonar.server.permission.PermissionChange.Operation.REMOVE; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; /** * Adds and removes user permissions. Both global and project scopes are supported. diff --git a/server/sonar-server/src/main/java/org/sonar/server/plugins/PluginDownloader.java b/server/sonar-server/src/main/java/org/sonar/server/plugins/PluginDownloader.java index c958b7c834b..d61efac304c 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/plugins/PluginDownloader.java +++ b/server/sonar-server/src/main/java/org/sonar/server/plugins/PluginDownloader.java @@ -45,7 +45,7 @@ import static org.apache.commons.io.FileUtils.forceMkdir; import static org.apache.commons.io.FileUtils.toFile; import static org.apache.commons.lang.StringUtils.substringAfterLast; import static org.sonar.core.util.FileUtils.deleteQuietly; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; /** * Downloads plugins from update center. Files are copied in the directory extensions/downloads and then diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGateConditionsUpdater.java b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGateConditionsUpdater.java index e4fd0b477c0..fb9400b9525 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGateConditionsUpdater.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGateConditionsUpdater.java @@ -56,7 +56,7 @@ import static org.sonar.server.measure.Rating.E; import static org.sonar.server.qualitygate.Condition.Operator.GREATER_THAN; import static org.sonar.server.qualitygate.Condition.Operator.LESS_THAN; import static org.sonar.server.qualitygate.ValidRatingMetrics.isCoreRatingMetric; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; public class QualityGateConditionsUpdater { diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java index 89ad36e61f5..43e795587ae 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java @@ -56,7 +56,7 @@ import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.NotFoundException; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; @ServerSide public class QProfileExporters { diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileFactoryImpl.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileFactoryImpl.java index aef07c464c5..580f13aa45e 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileFactoryImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileFactoryImpl.java @@ -39,7 +39,7 @@ import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.qualityprofile.index.ActiveRuleIndexer; import static com.google.common.base.Preconditions.checkArgument; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; public class QProfileFactoryImpl implements QProfileFactory { diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileTreeImpl.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileTreeImpl.java index b50a32a9d96..af5f778d0ed 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileTreeImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileTreeImpl.java @@ -33,7 +33,7 @@ import org.sonar.db.qualityprofile.QProfileDto; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.qualityprofile.index.ActiveRuleIndexer; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; public class QProfileTreeImpl implements QProfileTree { diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivationContext.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivationContext.java index c96a3c75ac4..28a55cdb37f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivationContext.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivationContext.java @@ -42,7 +42,7 @@ import static java.util.Objects.requireNonNull; import static org.sonar.core.util.stream.MoreCollectors.index; import static org.sonar.core.util.stream.MoreCollectors.toArrayList; import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; /** * Cache of the data required to activate/deactivate diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java index 8d36ea471c0..2b5a2f8e19f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java @@ -52,7 +52,7 @@ import org.sonar.server.user.UserSession; import org.sonar.server.util.TypeValidations; import static com.google.common.base.Preconditions.checkArgument; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; /** * Activation and deactivation of rules in Quality profiles diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/RuleCreator.java b/server/sonar-server/src/main/java/org/sonar/server/rule/RuleCreator.java index 691fccc29e8..5a4074a20bd 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/RuleCreator.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/RuleCreator.java @@ -49,7 +49,7 @@ import org.sonar.server.util.TypeValidations; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.collect.Lists.newArrayList; import static java.lang.String.format; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; @ServerSide public class RuleCreator { diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/UserUpdater.java b/server/sonar-server/src/main/java/org/sonar/server/user/UserUpdater.java index 7ed5e8d49d5..4c41bbd9ff7 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/user/UserUpdater.java +++ b/server/sonar-server/src/main/java/org/sonar/server/user/UserUpdater.java @@ -58,7 +58,7 @@ import static org.sonar.api.CoreProperties.DEFAULT_ISSUE_ASSIGNEE; import static org.sonar.core.util.Slug.slugify; import static org.sonar.core.util.stream.MoreCollectors.toList; import static org.sonar.process.ProcessProperties.Property.ONBOARDING_TUTORIAL_SHOW_TO_NEW_USERS; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; @ServerSide public class UserUpdater { diff --git a/server/sonar-server/src/main/java/org/sonar/server/util/BooleanTypeValidation.java b/server/sonar-server/src/main/java/org/sonar/server/util/BooleanTypeValidation.java index 6dee27fde5d..1b3ade32e60 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/util/BooleanTypeValidation.java +++ b/server/sonar-server/src/main/java/org/sonar/server/util/BooleanTypeValidation.java @@ -24,7 +24,7 @@ import javax.annotation.Nullable; import org.apache.commons.lang.StringUtils; import org.sonar.api.PropertyType; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; public class BooleanTypeValidation implements TypeValidation { diff --git a/server/sonar-server/src/main/java/org/sonar/server/util/StringListTypeValidation.java b/server/sonar-server/src/main/java/org/sonar/server/util/StringListTypeValidation.java index 48e224fb963..acb1c7dca8f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/util/StringListTypeValidation.java +++ b/server/sonar-server/src/main/java/org/sonar/server/util/StringListTypeValidation.java @@ -24,7 +24,7 @@ import javax.annotation.Nullable; import org.apache.commons.lang.StringUtils; import org.sonar.api.PropertyType; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; public class StringListTypeValidation implements TypeValidation { diff --git a/server/sonar-server/src/main/java/org/sonar/server/util/TypeValidations.java b/server/sonar-server/src/main/java/org/sonar/server/util/TypeValidations.java index 0766d073ed5..2c8883b77eb 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/util/TypeValidations.java +++ b/server/sonar-server/src/main/java/org/sonar/server/util/TypeValidations.java @@ -26,7 +26,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.sonar.api.server.ServerSide; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; @ServerSide public class TypeValidations { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/batch/ProjectDataLoader.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/batch/ProjectDataLoader.java index ae253385bb7..a262c8f7121 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/batch/ProjectDataLoader.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/batch/ProjectDataLoader.java @@ -41,7 +41,7 @@ import org.sonar.server.user.UserSession; import static com.google.common.collect.Maps.newHashMap; import static org.sonar.process.ProcessProperties.Property.SONARCLOUD_ENABLED; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; @ServerSide public class ProjectDataLoader { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/branch/ws/DeleteAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/branch/ws/DeleteAction.java index 5e0e6dae001..7c28dfe8a45 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/branch/ws/DeleteAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/branch/ws/DeleteAction.java @@ -40,7 +40,7 @@ import static org.sonar.server.branch.ws.ProjectBranchesParameters.ACTION_DELETE import static org.sonar.server.branch.ws.ProjectBranchesParameters.PARAM_BRANCH; import static org.sonar.server.branch.ws.ProjectBranchesParameters.PARAM_PROJECT; import static org.sonar.server.project.Project.from; -import static org.sonar.server.ws.WsUtils.checkFoundWithOptional; +import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; public class DeleteAction implements BranchWsAction { private final DbClient dbClient; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/ActivityAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/ActivityAction.java index cefe7441f2a..7053ba1757c 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/ActivityAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/ActivityAction.java @@ -67,8 +67,8 @@ import static org.sonar.server.ce.ws.CeWsParameters.PARAM_MIN_SUBMITTED_AT; import static org.sonar.server.ce.ws.CeWsParameters.PARAM_ONLY_CURRENTS; import static org.sonar.server.ce.ws.CeWsParameters.PARAM_STATUS; import static org.sonar.server.ce.ws.CeWsParameters.PARAM_TYPE; -import static org.sonar.server.ws.WsUtils.checkFoundWithOptional; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; import static org.sonar.server.ws.WsUtils.writeProtobuf; public class ActivityAction implements CeWsAction { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/AnalysisStatusAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/AnalysisStatusAction.java index dcedd00a345..3c360ae1e8b 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/AnalysisStatusAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/AnalysisStatusAction.java @@ -44,7 +44,7 @@ import static org.sonar.server.ce.ws.CeWsParameters.PARAM_COMPONENT; import static org.sonar.server.ce.ws.CeWsParameters.PARAM_PULL_REQUEST; import static org.sonar.server.ws.KeyExamples.KEY_BRANCH_EXAMPLE_001; import static org.sonar.server.ws.KeyExamples.KEY_PULL_REQUEST_EXAMPLE_001; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; import static org.sonar.server.ws.WsUtils.writeProtobuf; public class AnalysisStatusAction implements CeWsAction { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/SubmitAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/SubmitAction.java index a7c406ba8b5..06d721f9d43 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/SubmitAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/SubmitAction.java @@ -38,7 +38,7 @@ import static org.apache.commons.lang.StringUtils.abbreviate; import static org.apache.commons.lang.StringUtils.defaultIfBlank; import static org.sonar.core.component.ComponentKeys.MAX_COMPONENT_KEY_LENGTH; import static org.sonar.db.component.ComponentValidator.MAX_COMPONENT_NAME_LENGTH; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; public class SubmitAction implements CeWsAction { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/TaskAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/TaskAction.java index 3d726449afa..8ad0f2f58d3 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/TaskAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/TaskAction.java @@ -42,8 +42,8 @@ import org.sonar.db.ce.CeQueueDto; import org.sonar.db.ce.CeTaskMessageDto; import org.sonar.db.component.ComponentDto; import org.sonar.db.permission.OrganizationPermission; +import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.user.UserSession; -import org.sonar.server.ws.WsUtils; import org.sonarqube.ws.Ce; import static org.sonar.server.user.AbstractUserSession.insufficientPrivilegesException; @@ -100,7 +100,7 @@ public class TaskAction implements CeWsAction { checkPermission(component); wsTaskResponse.setTask(wsTaskFormatter.formatQueue(dbSession, queueDto.get())); } else { - CeActivityDto ceActivityDto = WsUtils.checkFoundWithOptional(dbClient.ceActivityDao().selectByUuid(dbSession, taskUuid), "No activity found for task '%s'", taskUuid); + CeActivityDto ceActivityDto = NotFoundException.checkFoundWithOptional(dbClient.ceActivityDao().selectByUuid(dbSession, taskUuid), "No activity found for task '%s'", taskUuid); Optional<ComponentDto> component = loadComponent(dbSession, ceActivityDto.getComponentUuid()); checkPermission(component); Set<AdditionalField> additionalFields = AdditionalField.getFromRequest(wsRequest); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java index f695b3e1472..55fbe2b19ee 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java @@ -43,8 +43,8 @@ import org.sonar.server.component.index.ComponentIndex; import org.sonar.server.component.index.ComponentQuery; import org.sonar.server.es.SearchIdResult; import org.sonar.server.es.SearchOptions; +import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.organization.DefaultOrganizationProvider; -import org.sonar.server.ws.WsUtils; import org.sonarqube.ws.Components; import org.sonarqube.ws.Components.SearchWsResponse; @@ -164,7 +164,7 @@ public class SearchAction implements ComponentsWsAction { private OrganizationDto getOrganization(DbSession dbSession, SearchRequest request) { String organizationKey = Optional.ofNullable(request.getOrganization()) .orElseGet(defaultOrganizationProvider.get()::getKey); - return WsUtils.checkFoundWithOptional( + return NotFoundException.checkFoundWithOptional( dbClient.organizationDao().selectByKey(dbSession, organizationKey), "No organizationDto with key '%s'", organizationKey); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java index 72491ccf7c7..5a5fc63057f 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java @@ -83,13 +83,12 @@ import static org.sonar.server.component.ws.ProjectMeasuresQueryValidator.NON_ME import static org.sonar.server.measure.index.ProjectMeasuresIndex.SUPPORTED_FACETS; import static org.sonar.server.measure.index.ProjectMeasuresQuery.SORT_BY_LAST_ANALYSIS_DATE; import static org.sonar.server.measure.index.ProjectMeasuresQuery.SORT_BY_NAME; -import static org.sonar.server.ws.WsUtils.checkFound; -import static org.sonar.server.ws.WsUtils.checkFoundWithOptional; +import static org.sonar.server.exceptions.NotFoundException.checkFound; +import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; import static org.sonar.server.ws.WsUtils.writeProtobuf; import static org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_SEARCH_PROJECTS; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_FILTER; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_ORGANIZATION; -import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_QUALIFIERS; import static org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_LANGUAGES; import static org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_TAGS; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/AssignAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/AssignAction.java index cb4c4268f0f..1c917a0d487 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/AssignAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/AssignAction.java @@ -46,7 +46,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Strings.emptyToNull; import static java.lang.String.format; import static java.util.Objects.requireNonNull; -import static org.sonar.server.ws.WsUtils.checkFound; +import static org.sonar.server.exceptions.NotFoundException.checkFound; import static org.sonarqube.ws.client.issue.IssuesWsParameters.ACTION_ASSIGN; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ASSIGNEE; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ISSUE; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/AuthorsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/AuthorsAction.java index 6e97a07cba7..a88ef909c53 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/AuthorsAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/AuthorsAction.java @@ -47,7 +47,7 @@ import static java.util.Optional.ofNullable; import static org.sonar.api.server.ws.WebService.Param.PAGE_SIZE; import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY; import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; -import static org.sonar.server.ws.WsUtils.checkFoundWithOptional; +import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; import static org.sonar.server.ws.WsUtils.writeProtobuf; public class AuthorsAction implements IssuesWsAction { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/TagsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/TagsAction.java index 9fae3e598d0..8937dc644b7 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/TagsAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/TagsAction.java @@ -44,7 +44,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static org.sonar.api.server.ws.WebService.Param.PAGE_SIZE; import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY; import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; -import static org.sonar.server.ws.WsUtils.checkFoundWithOptional; +import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; import static org.sonar.server.ws.WsUtils.writeProtobuf; /** diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/custom/ws/CreateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/custom/ws/CreateAction.java index 1db81b88956..b503154618c 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/custom/ws/CreateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/custom/ws/CreateAction.java @@ -41,7 +41,7 @@ import static org.sonar.server.component.ComponentFinder.ParamNames.PROJECT_ID_A import static org.sonar.server.measure.custom.ws.CustomMeasureValidator.checkPermissions; import static org.sonar.server.measure.custom.ws.CustomMeasureValueDescription.measureValueDescription; import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; public class CreateAction implements CustomMeasuresWsAction { public static final String ACTION = "create"; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java index 123d929bcf3..a34da0fdb0f 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java @@ -81,7 +81,7 @@ import static org.sonar.server.measure.ws.SnapshotDtoToWsPeriod.snapshotToWsPeri import static org.sonar.server.ws.KeyExamples.KEY_BRANCH_EXAMPLE_001; import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; import static org.sonar.server.ws.KeyExamples.KEY_PULL_REQUEST_EXAMPLE_001; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; import static org.sonar.server.ws.WsUtils.writeProtobuf; public class ComponentAction implements MeasuresWsAction { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java index db8e9ed0b56..fb843ebe1b3 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java @@ -113,7 +113,7 @@ import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; import static org.sonar.server.ws.KeyExamples.KEY_PULL_REQUEST_EXAMPLE_001; import static org.sonar.server.ws.WsParameterBuilder.createQualifiersParameter; import static org.sonar.server.ws.WsParameterBuilder.QualifierParameterContext.newQualifierParameterContext; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; import static org.sonar.server.ws.WsUtils.writeProtobuf; /** diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchAction.java index 06b12c9fdd6..88634284ba5 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchAction.java @@ -53,7 +53,7 @@ import static org.sonar.server.measure.ws.MeasureDtoToWsMeasure.updateMeasureBui import static org.sonar.server.measure.ws.MeasuresWsParametersBuilder.createMetricKeysParameter; import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_002; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; import static org.sonar.server.ws.WsUtils.writeProtobuf; import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_METRIC_KEYS; import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_PROJECT_KEYS; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/CreateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/CreateAction.java index 1bcba8cf613..c10b3bee4f7 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/CreateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/CreateAction.java @@ -38,7 +38,7 @@ import static org.sonar.db.metric.MetricValidator.MAX_DOMAIN_LENGTH; import static org.sonar.db.metric.MetricValidator.MAX_KEY_LENGTH; import static org.sonar.db.metric.MetricValidator.MAX_NAME_LENGTH; import static org.sonar.server.util.MetricKeyValidator.checkMetricKeyFormat; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; public class CreateAction implements MetricsWsAction { private static final String ACTION = "create"; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/UpdateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/UpdateAction.java index 128e353effa..e75508ea892 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/UpdateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/UpdateAction.java @@ -37,7 +37,7 @@ import static org.sonar.db.metric.MetricValidator.MAX_DESCRIPTION_LENGTH; import static org.sonar.db.metric.MetricValidator.MAX_DOMAIN_LENGTH; import static org.sonar.db.metric.MetricValidator.MAX_KEY_LENGTH; import static org.sonar.db.metric.MetricValidator.MAX_NAME_LENGTH; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; public class UpdateAction implements MetricsWsAction { private static final String ACTION = "update"; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/AddAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/AddAction.java index a17fb840b03..7cc59d0c9bc 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/AddAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/AddAction.java @@ -45,8 +45,8 @@ import static org.sonar.server.notification.ws.NotificationsWsParameters.PARAM_C import static org.sonar.server.notification.ws.NotificationsWsParameters.PARAM_LOGIN; import static org.sonar.server.notification.ws.NotificationsWsParameters.PARAM_PROJECT; import static org.sonar.server.notification.ws.NotificationsWsParameters.PARAM_TYPE; -import static org.sonar.server.ws.WsUtils.checkFound; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.NotFoundException.checkFound; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; public class AddAction implements NotificationsWsAction { private final NotificationCenter notificationCenter; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/ListAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/ListAction.java index bbb62c039a4..015742db8f8 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/ListAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/ListAction.java @@ -54,7 +54,7 @@ import static java.util.Optional.ofNullable; import static org.sonar.core.util.stream.MoreCollectors.toOneElement; import static org.sonar.server.notification.ws.NotificationsWsParameters.ACTION_LIST; import static org.sonar.server.notification.ws.NotificationsWsParameters.PARAM_LOGIN; -import static org.sonar.server.ws.WsUtils.checkFound; +import static org.sonar.server.exceptions.NotFoundException.checkFound; import static org.sonar.server.ws.WsUtils.writeProtobuf; public class ListAction implements NotificationsWsAction { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/RemoveAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/RemoveAction.java index 0713dd3d4f8..5e1a8605935 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/RemoveAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/RemoveAction.java @@ -45,8 +45,8 @@ import static org.sonar.server.notification.ws.NotificationsWsParameters.PARAM_C import static org.sonar.server.notification.ws.NotificationsWsParameters.PARAM_LOGIN; import static org.sonar.server.notification.ws.NotificationsWsParameters.PARAM_PROJECT; import static org.sonar.server.notification.ws.NotificationsWsParameters.PARAM_TYPE; -import static org.sonar.server.ws.WsUtils.checkFound; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.NotFoundException.checkFound; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; public class RemoveAction implements NotificationsWsAction { private final NotificationCenter notificationCenter; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/organization/ws/AddMemberAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/organization/ws/AddMemberAction.java index b1740833e5f..a2bcc20989b 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/organization/ws/AddMemberAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/organization/ws/AddMemberAction.java @@ -41,8 +41,8 @@ import static org.sonar.db.user.GroupMembershipQuery.IN; import static org.sonar.server.organization.ws.OrganizationsWsSupport.PARAM_LOGIN; import static org.sonar.server.organization.ws.OrganizationsWsSupport.PARAM_ORGANIZATION; import static org.sonar.server.ws.KeyExamples.KEY_ORG_EXAMPLE_001; -import static org.sonar.server.ws.WsUtils.checkFound; -import static org.sonar.server.ws.WsUtils.checkFoundWithOptional; +import static org.sonar.server.exceptions.NotFoundException.checkFound; +import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; import static org.sonar.server.ws.WsUtils.writeProtobuf; public class AddMemberAction implements OrganizationsWsAction { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/organization/ws/DeleteAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/organization/ws/DeleteAction.java index 9d76d8adf9c..d61336cfd1f 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/organization/ws/DeleteAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/organization/ws/DeleteAction.java @@ -35,7 +35,7 @@ import static org.sonar.db.permission.OrganizationPermission.ADMINISTER; import static org.sonar.server.organization.ws.OrganizationsWsSupport.PARAM_KEY; import static org.sonar.server.organization.ws.OrganizationsWsSupport.PARAM_ORGANIZATION; import static org.sonar.server.ws.KeyExamples.KEY_ORG_EXAMPLE_002; -import static org.sonar.server.ws.WsUtils.checkFoundWithOptional; +import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; public class DeleteAction implements OrganizationsWsAction { private static final String ACTION = "delete"; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/organization/ws/RemoveMemberAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/organization/ws/RemoveMemberAction.java index 405c0098cf0..10d3df8463e 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/organization/ws/RemoveMemberAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/organization/ws/RemoveMemberAction.java @@ -34,8 +34,8 @@ import static org.sonar.db.permission.OrganizationPermission.ADMINISTER; import static org.sonar.server.organization.ws.OrganizationsWsSupport.PARAM_LOGIN; import static org.sonar.server.organization.ws.OrganizationsWsSupport.PARAM_ORGANIZATION; import static org.sonar.server.ws.KeyExamples.KEY_ORG_EXAMPLE_001; -import static org.sonar.server.ws.WsUtils.checkFound; -import static org.sonar.server.ws.WsUtils.checkFoundWithOptional; +import static org.sonar.server.exceptions.NotFoundException.checkFound; +import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; public class RemoveMemberAction implements OrganizationsWsAction { private final DbClient dbClient; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/organization/ws/SearchMembersAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/organization/ws/SearchMembersAction.java index 70cc2b0f3ef..4a2c55ed3b4 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/organization/ws/SearchMembersAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/organization/ws/SearchMembersAction.java @@ -54,7 +54,7 @@ import static org.sonar.api.server.ws.WebService.SelectionMode.SELECTED; import static org.sonar.db.permission.OrganizationPermission.ADMINISTER; import static org.sonar.server.es.SearchOptions.MAX_LIMIT; import static org.sonar.server.organization.ws.OrganizationsWsSupport.PARAM_ORGANIZATION; -import static org.sonar.server.ws.WsUtils.checkFoundWithOptional; +import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; import static org.sonar.server.ws.WsUtils.writeProtobuf; public class SearchMembersAction implements OrganizationsWsAction { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java index d7a50e52d48..6bbc3e76414 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java @@ -38,7 +38,7 @@ import org.sonar.server.usergroups.ws.GroupWsSupport; import org.sonarqube.ws.client.permission.PermissionsWsParameters; import static com.google.common.base.Preconditions.checkArgument; -import static org.sonar.server.ws.WsUtils.checkFound; +import static org.sonar.server.exceptions.NotFoundException.checkFound; import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_ID; import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_NAME; import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_ORGANIZATION; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/ProjectWsRef.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/ProjectWsRef.java index 088c8e1cae2..2edea3b48c9 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/ProjectWsRef.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/ProjectWsRef.java @@ -23,7 +23,7 @@ import com.google.common.base.Optional; import javax.annotation.CheckForNull; import javax.annotation.Nullable; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; /** * Reference to a project <b>as defined by web service callers</b>. It allows to reference a project diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/AddGroupToTemplateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/AddGroupToTemplateAction.java index 0fa3c6347fe..b897e25730b 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/AddGroupToTemplateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/AddGroupToTemplateAction.java @@ -38,7 +38,7 @@ import static org.sonar.server.permission.ws.WsParameters.createGroupIdParameter import static org.sonar.server.permission.ws.WsParameters.createGroupNameParameter; import static org.sonar.server.permission.ws.WsParameters.createTemplateParameters; import static org.sonar.server.permission.ws.template.WsTemplateRef.fromRequest; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION; public class AddGroupToTemplateAction implements PermissionsWsAction { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/CreateTemplateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/CreateTemplateAction.java index ddda5a51086..4f45de04cb1 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/CreateTemplateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/CreateTemplateAction.java @@ -44,7 +44,7 @@ import static java.util.Objects.requireNonNull; import static org.sonar.server.permission.PermissionPrivilegeChecker.checkGlobalAdmin; import static org.sonar.server.permission.RequestValidator.MSG_TEMPLATE_WITH_SAME_NAME; import static org.sonar.server.permission.ws.template.PermissionTemplateDtoToPermissionTemplateResponse.toPermissionTemplateResponse; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; import static org.sonar.server.ws.WsUtils.writeProtobuf; import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_DESCRIPTION; import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_NAME; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/DeleteTemplateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/DeleteTemplateAction.java index eb816ff78d5..642f224b962 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/DeleteTemplateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/DeleteTemplateAction.java @@ -37,8 +37,8 @@ import org.sonar.server.user.UserSession; import static org.sonar.server.permission.PermissionPrivilegeChecker.checkGlobalAdmin; import static org.sonar.server.permission.ws.template.WsTemplateRef.newTemplateRef; -import static org.sonar.server.ws.WsUtils.checkFoundWithOptional; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_ORGANIZATION; import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_ID; import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_NAME; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/SearchTemplatesAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/SearchTemplatesAction.java index a62b35ff977..686187acba7 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/SearchTemplatesAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/SearchTemplatesAction.java @@ -56,7 +56,7 @@ import static java.util.Optional.ofNullable; import static org.sonar.api.utils.DateUtils.formatDateTime; import static org.sonar.server.permission.PermissionPrivilegeChecker.checkGlobalAdmin; import static org.sonar.server.permission.ws.template.SearchTemplatesData.builder; -import static org.sonar.server.ws.WsUtils.checkFoundWithOptional; +import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; import static org.sonar.server.ws.WsUtils.writeProtobuf; import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_ORGANIZATION; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/SetDefaultTemplateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/SetDefaultTemplateAction.java index 3c8d160b7c0..0b89cd8817d 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/SetDefaultTemplateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/SetDefaultTemplateAction.java @@ -42,7 +42,7 @@ import static org.sonar.server.permission.PermissionPrivilegeChecker.checkGlobal import static org.sonar.server.permission.ws.template.WsTemplateRef.newTemplateRef; import static org.sonar.server.ws.WsParameterBuilder.createDefaultTemplateQualifierParameter; import static org.sonar.server.ws.WsParameterBuilder.QualifierParameterContext.newQualifierParameterContext; -import static org.sonar.server.ws.WsUtils.checkFoundWithOptional; +import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_ORGANIZATION; import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_QUALIFIER; import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_ID; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/UpdateTemplateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/UpdateTemplateAction.java index 0508ec5e220..18ce2e5f219 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/UpdateTemplateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/UpdateTemplateAction.java @@ -29,12 +29,12 @@ import org.sonar.api.utils.System2; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.permission.template.PermissionTemplateDto; +import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.permission.ws.PermissionWsSupport; import org.sonar.server.permission.ws.PermissionsWsAction; import org.sonar.server.permission.RequestValidator; import org.sonar.server.permission.ws.WsParameters; import org.sonar.server.user.UserSession; -import org.sonar.server.ws.WsUtils; import org.sonarqube.ws.Permissions.PermissionTemplate; import org.sonarqube.ws.Permissions.UpdateTemplateWsResponse; @@ -45,7 +45,7 @@ import static org.apache.commons.lang.StringUtils.isBlank; import static org.sonar.server.permission.PermissionPrivilegeChecker.checkGlobalAdmin; import static org.sonar.server.permission.RequestValidator.MSG_TEMPLATE_WITH_SAME_NAME; import static org.sonar.server.permission.ws.template.PermissionTemplateDtoToPermissionTemplateResponse.toPermissionTemplateResponse; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; import static org.sonar.server.ws.WsUtils.writeProtobuf; import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_DESCRIPTION; import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_ID; @@ -143,7 +143,7 @@ public class UpdateTemplateAction implements PermissionsWsAction { } private void validateTemplateNameForUpdate(DbSession dbSession, String organizationUuid, String name, long id) { - WsUtils.checkRequest(!isBlank(name), "The template name must not be blank"); + BadRequestException.checkRequest(!isBlank(name), "The template name must not be blank"); PermissionTemplateDto permissionTemplateWithSameName = dbClient.permissionTemplateDao().selectByName(dbSession, organizationUuid, name); checkRequest(permissionTemplateWithSameName == null || permissionTemplateWithSameName.getId() == id, diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/WsTemplateRef.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/WsTemplateRef.java index d04209d4dda..36eb2e9faf1 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/WsTemplateRef.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/WsTemplateRef.java @@ -23,7 +23,7 @@ import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.sonar.api.server.ws.Request; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_ORGANIZATION; import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_ID; import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_NAME; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/BulkUpdateKeyAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/BulkUpdateKeyAction.java index fd7a9187211..0adba9f7f09 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/BulkUpdateKeyAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/BulkUpdateKeyAction.java @@ -37,7 +37,7 @@ import org.sonarqube.ws.Projects.BulkUpdateKeyWsResponse; import static com.google.common.base.Preconditions.checkArgument; import static org.sonar.db.component.ComponentKeyUpdaterDao.checkIsProjectOrModule; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; import static org.sonar.server.ws.WsUtils.writeProtobuf; import static org.sonarqube.ws.client.project.ProjectsWsParameters.ACTION_BULK_UPDATE_KEY; import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_DRY_RUN; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/ProjectsWsSupport.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/ProjectsWsSupport.java index fcbfe4cf3b4..f20baa2df8c 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/ProjectsWsSupport.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/ProjectsWsSupport.java @@ -29,7 +29,7 @@ import org.sonar.server.organization.BillingValidations; import org.sonar.server.organization.BillingValidationsProxy; import org.sonar.server.organization.DefaultOrganizationProvider; -import static org.sonar.server.ws.WsUtils.checkFoundWithOptional; +import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; @ServerSide public class ProjectsWsSupport { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateDefaultVisibilityAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateDefaultVisibilityAction.java index 88a695b7a8b..ec2b999cd8f 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateDefaultVisibilityAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateDefaultVisibilityAction.java @@ -32,7 +32,7 @@ import org.sonar.server.project.Visibility; import org.sonar.server.user.UserSession; import static org.sonar.server.user.AbstractUserSession.insufficientPrivilegesException; -import static org.sonar.server.ws.WsUtils.checkFoundWithOptional; +import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; public class UpdateDefaultVisibilityAction implements ProjectsWsAction { static final String ACTION = "update_default_visibility"; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java index f5416d4671d..77579eb9e95 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java @@ -45,7 +45,7 @@ import static java.lang.String.format; import static java.util.Collections.singletonList; import static org.sonar.api.web.UserRole.PUBLIC_PERMISSIONS; import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_PROJECT; import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_VISIBILITY; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/projectlink/ws/DeleteAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/projectlink/ws/DeleteAction.java index 58d3ed3a5a5..67f8484bfc9 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/projectlink/ws/DeleteAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/projectlink/ws/DeleteAction.java @@ -26,8 +26,9 @@ import org.sonar.api.web.UserRole; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.component.ProjectLinkDto; +import org.sonar.server.exceptions.BadRequestException; +import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.user.UserSession; -import org.sonar.server.ws.WsUtils; import static org.sonar.db.component.ProjectLinkDto.PROVIDED_TYPES; import static org.sonar.server.projectlink.ws.ProjectLinksWsParameters.ACTION_DELETE; @@ -68,7 +69,7 @@ public class DeleteAction implements ProjectLinksWsAction { try (DbSession dbSession = dbClient.openSession(false)) { ProjectLinkDto link = dbClient.projectLinkDao().selectByUuid(dbSession, id); - link = WsUtils.checkFound(link, "Link with id '%s' not found", id); + link = NotFoundException.checkFound(link, "Link with id '%s' not found", id); checkProjectAdminPermission(link); checkNotProvided(link); @@ -80,7 +81,7 @@ public class DeleteAction implements ProjectLinksWsAction { private static void checkNotProvided(ProjectLinkDto link) { String type = link.getType(); boolean isProvided = type != null && PROVIDED_TYPES.contains(type); - WsUtils.checkRequest(!isProvided, "Provided link cannot be deleted."); + BadRequestException.checkRequest(!isProvided, "Provided link cannot be deleted."); } private void checkProjectAdminPermission(ProjectLinkDto link) { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/projectlink/ws/ProjectLinksWs.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/projectlink/ws/ProjectLinksWs.java index de038d84183..fcbaef0d9f3 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/projectlink/ws/ProjectLinksWs.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/projectlink/ws/ProjectLinksWs.java @@ -25,7 +25,7 @@ import org.sonar.api.server.ws.WebService; import org.sonar.db.component.ComponentDto; import static java.lang.String.format; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; public class ProjectLinksWs implements WebService { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/projecttag/ws/SetAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/projecttag/ws/SetAction.java index d2812b0cb48..698970dbc0f 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/projecttag/ws/SetAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/projecttag/ws/SetAction.java @@ -38,7 +38,7 @@ import static java.util.Collections.singletonList; import static org.sonar.api.resources.Qualifiers.PROJECT; import static org.sonar.server.es.ProjectIndexer.Cause.PROJECT_TAGS_UPDATE; import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; public class SetAction implements ProjectTagsWsAction { /** diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ProjectStatusAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ProjectStatusAction.java index 904ade20796..f275f526da7 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ProjectStatusAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ProjectStatusAction.java @@ -51,8 +51,8 @@ import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_PRO import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_PROJECT_KEY; import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_PULL_REQUEST; import static org.sonar.server.user.AbstractUserSession.insufficientPrivilegesException; -import static org.sonar.server.ws.WsUtils.checkFoundWithOptional; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; import static org.sonar.server.ws.WsUtils.writeProtobuf; public class ProjectStatusAction implements QualityGatesWsAction { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/QualityGatesWsSupport.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/QualityGatesWsSupport.java index 92170f83fd1..5b0bf8f7ccb 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/QualityGatesWsSupport.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/QualityGatesWsSupport.java @@ -43,8 +43,8 @@ import static org.sonar.db.organization.OrganizationDto.Subscription.PAID; import static org.sonar.db.permission.OrganizationPermission.ADMINISTER_QUALITY_GATES; import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_ORGANIZATION; import static org.sonar.server.user.AbstractUserSession.insufficientPrivilegesException; -import static org.sonar.server.ws.WsUtils.checkFound; -import static org.sonar.server.ws.WsUtils.checkFoundWithOptional; +import static org.sonar.server.exceptions.NotFoundException.checkFound; +import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; public class QualityGatesWsSupport { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ShowAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ShowAction.java index d751010d5ff..892de9f147b 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ShowAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ShowAction.java @@ -46,7 +46,7 @@ import static org.sonar.core.util.stream.MoreCollectors.toSet; import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex; import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_ID; import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_NAME; -import static org.sonar.server.ws.WsUtils.checkFound; +import static org.sonar.server.exceptions.NotFoundException.checkFound; import static org.sonar.server.ws.WsUtils.writeProtobuf; public class ShowAction implements QualityGatesWsAction { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ExportAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ExportAction.java index 114baed2168..b7a47fcdfa6 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ExportAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ExportAction.java @@ -49,8 +49,8 @@ import org.sonarqube.ws.MediaTypes; import static java.nio.charset.StandardCharsets.UTF_8; import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01; import static org.sonar.server.qualityprofile.ws.QProfileWsSupport.createOrganizationParam; -import static org.sonar.server.ws.WsUtils.checkFound; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.NotFoundException.checkFound; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_ORGANIZATION; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_KEY; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LANGUAGE; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/QProfileWsSupport.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/QProfileWsSupport.java index 7b41142f03a..7aa34505534 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/QProfileWsSupport.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/QProfileWsSupport.java @@ -41,9 +41,9 @@ import static com.google.common.base.Preconditions.checkState; import static java.util.Objects.requireNonNull; import static org.sonar.db.organization.OrganizationDto.Subscription.PAID; import static org.sonar.server.user.AbstractUserSession.insufficientPrivilegesException; -import static org.sonar.server.ws.WsUtils.checkFound; -import static org.sonar.server.ws.WsUtils.checkFoundWithOptional; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.NotFoundException.checkFound; +import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_ORGANIZATION; @ServerSide diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/RenameAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/RenameAction.java index 05e8497628e..1166f899fe7 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/RenameAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/RenameAction.java @@ -34,7 +34,7 @@ import static java.lang.String.format; import static java.util.Optional.ofNullable; import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01; import static org.sonar.server.qualityprofile.ws.CreateAction.NAME_MAXIMUM_LENGTH; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_KEY; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_NAME; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ShowAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ShowAction.java index 24946d83c68..5c4822be8f5 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ShowAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ShowAction.java @@ -48,7 +48,7 @@ import static java.util.Optional.ofNullable; import static org.sonar.api.rule.RuleStatus.DEPRECATED; import static org.sonar.api.utils.DateUtils.formatDateTime; import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01; -import static org.sonar.server.ws.WsUtils.checkFound; +import static org.sonar.server.exceptions.NotFoundException.checkFound; import static org.sonar.server.ws.WsUtils.writeProtobuf; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_SHOW; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_COMPARE_TO_SONAR_WAY; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/root/ws/UnsetRootAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/root/ws/UnsetRootAction.java index be8a0d83d70..3d0def5c484 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/root/ws/UnsetRootAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/root/ws/UnsetRootAction.java @@ -29,7 +29,7 @@ import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.user.UserSession; import static java.lang.String.format; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; public class UnsetRootAction implements RootsWsAction { private static final String PARAM_LOGIN = "login"; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleQueryFactory.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleQueryFactory.java index 35482f639be..31db584f037 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleQueryFactory.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleQueryFactory.java @@ -56,8 +56,8 @@ import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_TAGS; import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_TEMPLATE_KEY; import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_TYPES; import static org.sonar.server.util.EnumUtils.toEnums; -import static org.sonar.server.ws.WsUtils.checkFound; -import static org.sonar.server.ws.WsUtils.checkFoundWithOptional; +import static org.sonar.server.exceptions.NotFoundException.checkFound; +import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; @ServerSide public class RuleQueryFactory { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleWsSupport.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleWsSupport.java index 551548eee01..b7288a6ec0d 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleWsSupport.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleWsSupport.java @@ -75,7 +75,7 @@ import static org.sonar.server.security.SecurityStandardHelper.SANS_TOP_25_CWE_M import static org.sonar.server.security.SecurityStandardHelper.SONARSOURCE_CWE_MAPPING; import static org.sonar.server.security.SecurityStandardHelper.SONARSOURCE_OTHER_CWES_CATEGORY; import static org.sonar.server.security.SecurityStandardHelper.UNKNOWN_STANDARD; -import static org.sonar.server.ws.WsUtils.checkFoundWithOptional; +import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; @ServerSide public class RuleWsSupport { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/TagsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/TagsAction.java index c1295b40356..0ef19b89620 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/TagsAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/TagsAction.java @@ -32,9 +32,9 @@ import org.sonar.api.utils.text.JsonWriter; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.organization.OrganizationDto; +import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.organization.DefaultOrganizationProvider; import org.sonar.server.rule.index.RuleIndex; -import org.sonar.server.ws.WsUtils; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_ORGANIZATION; @@ -85,7 +85,7 @@ public class TagsAction implements RulesWsAction { try (DbSession dbSession = dbClient.openSession(false)) { String organizationOrDefaultKey = Optional.ofNullable(organizationKey) .orElseGet(defaultOrganizationProvider.get()::getKey); - return WsUtils.checkFoundWithOptional( + return NotFoundException.checkFoundWithOptional( dbClient.organizationDao().selectByKey(dbSession, organizationOrDefaultKey), "No organization with key '%s'", organizationOrDefaultKey); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/EncryptAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/EncryptAction.java index 314fff12448..240b612887b 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/EncryptAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/EncryptAction.java @@ -28,7 +28,7 @@ import org.sonar.server.user.UserSession; import org.sonarqube.ws.Settings.EncryptWsResponse; import static org.sonar.server.setting.ws.SettingsWsParameters.PARAM_VALUE; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; import static org.sonar.server.ws.WsUtils.writeProtobuf; public class EncryptAction implements SettingsWsAction { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SetAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SetAction.java index 346d367a2ac..f05bffcb860 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SetAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SetAction.java @@ -67,7 +67,7 @@ import static org.sonar.server.setting.ws.SettingsWsParameters.PARAM_PULL_REQUES import static org.sonar.server.setting.ws.SettingsWsParameters.PARAM_VALUE; import static org.sonar.server.setting.ws.SettingsWsParameters.PARAM_VALUES; import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; public class SetAction implements SettingsWsAction { private static final Collector<CharSequence, ?, String> COMMA_JOINER = Collectors.joining(","); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SettingValidations.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SettingValidations.java index e8aeae8218c..ec3553cf38c 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SettingValidations.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SettingValidations.java @@ -42,7 +42,7 @@ import org.sonar.server.exceptions.BadRequestException; import static java.lang.String.format; import static java.util.Objects.requireNonNull; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; public class SettingValidations { private final PropertyDefinitions definitions; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/LinesAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/LinesAction.java index a7ecc8cb5ee..289055ad90a 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/LinesAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/LinesAction.java @@ -44,8 +44,8 @@ import static org.sonar.server.component.ComponentFinder.ParamNames.UUID_AND_KEY import static org.sonar.server.ws.KeyExamples.KEY_BRANCH_EXAMPLE_001; import static org.sonar.server.ws.KeyExamples.KEY_FILE_EXAMPLE_001; import static org.sonar.server.ws.KeyExamples.KEY_PULL_REQUEST_EXAMPLE_001; -import static org.sonar.server.ws.WsUtils.checkFoundWithOptional; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; public class LinesAction implements SourcesWsAction { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/ScmAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/ScmAction.java index 1112ef9b273..0bd5ce32016 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/ScmAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/ScmAction.java @@ -38,7 +38,7 @@ import org.sonar.server.component.ComponentFinder; import org.sonar.server.source.SourceService; import org.sonar.server.user.UserSession; -import static org.sonar.server.ws.WsUtils.checkFoundWithOptional; +import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; public class ScmAction implements SourcesWsAction { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/ShowAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/ShowAction.java index 6d9208856f8..ec1682b1fdd 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/ShowAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/ShowAction.java @@ -33,7 +33,7 @@ import org.sonar.server.component.ComponentFinder; import org.sonar.server.source.SourceService; import org.sonar.server.user.UserSession; -import static org.sonar.server.ws.WsUtils.checkFoundWithOptional; +import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; public class ShowAction implements SourcesWsAction { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java index 3083e4e34e1..efa0e7ef96d 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java @@ -53,6 +53,7 @@ import org.sonar.db.property.PropertyQuery; import org.sonar.db.qualitygate.QualityGateDto; import org.sonar.db.qualityprofile.QProfileDto; import org.sonar.server.component.ComponentFinder; +import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.organization.BillingValidations; import org.sonar.server.organization.BillingValidationsProxy; @@ -62,7 +63,6 @@ import org.sonar.server.qualityprofile.QPMeasureData; import org.sonar.server.qualityprofile.QualityProfile; import org.sonar.server.ui.PageRepository; import org.sonar.server.user.UserSession; -import org.sonar.server.ws.WsUtils; import static java.lang.String.format; import static java.util.Collections.emptySortedSet; @@ -179,7 +179,7 @@ public class ComponentAction implements NavigationWsAction { } private static void checkComponentNotAModuleAndNotADirectory(ComponentDto component) { - WsUtils.checkRequest(!MODULE_OR_DIR_QUALIFIERS.contains(component.qualifier()), "Operation not supported for module or directory components"); + BadRequestException.checkRequest(!MODULE_OR_DIR_QUALIFIERS.contains(component.qualifier()), "Operation not supported for module or directory components"); } private ComponentDto getRootProjectOrBranch(ComponentDto component, DbSession session) { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/OrganizationAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/OrganizationAction.java index 19d4b8a9a19..09860411c34 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/OrganizationAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/OrganizationAction.java @@ -46,7 +46,7 @@ import org.sonar.server.user.UserSession; import static org.sonar.db.organization.OrganizationDto.Subscription.PAID; import static org.sonar.db.permission.OrganizationPermission.ADMINISTER; import static org.sonar.server.ws.KeyExamples.KEY_ORG_EXAMPLE_001; -import static org.sonar.server.ws.WsUtils.checkFoundWithOptional; +import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; public class OrganizationAction implements NavigationWsAction { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/DeactivateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/DeactivateAction.java index b14463ecd7c..6b3d29f6292 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/DeactivateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/DeactivateAction.java @@ -47,8 +47,8 @@ import static java.lang.String.format; import static java.util.Collections.singletonList; import static org.sonar.api.CoreProperties.DEFAULT_ISSUE_ASSIGNEE; import static org.sonar.process.ProcessProperties.Property.SONARCLOUD_ENABLED; -import static org.sonar.server.ws.WsUtils.checkFound; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.NotFoundException.checkFound; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; public class DeactivateAction implements UsersWsAction { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/GroupsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/GroupsAction.java index 2e55570e902..ea4b251fa48 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/GroupsAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/GroupsAction.java @@ -52,8 +52,8 @@ import static org.sonar.api.server.ws.WebService.Param.PAGE_SIZE; import static org.sonar.api.server.ws.WebService.Param.SELECTED; import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY; import static org.sonar.api.utils.Paging.forPageIndex; -import static org.sonar.server.ws.WsUtils.checkFound; -import static org.sonar.server.ws.WsUtils.checkFoundWithOptional; +import static org.sonar.server.exceptions.NotFoundException.checkFound; +import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; import static org.sonar.server.ws.WsUtils.writeProtobuf; import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_LOGIN; import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_ORGANIZATION; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/AddUserAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/AddUserAction.java index b17c549cc5b..e39b0e28a17 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/AddUserAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/AddUserAction.java @@ -41,7 +41,7 @@ import static org.sonar.server.usergroups.ws.GroupWsSupport.PARAM_LOGIN; import static org.sonar.server.usergroups.ws.GroupWsSupport.PARAM_ORGANIZATION_KEY; import static org.sonar.server.usergroups.ws.GroupWsSupport.defineGroupWsParameters; import static org.sonar.server.usergroups.ws.GroupWsSupport.defineLoginWsParameter; -import static org.sonar.server.ws.WsUtils.checkFound; +import static org.sonar.server.exceptions.NotFoundException.checkFound; public class AddUserAction implements UserGroupsWsAction { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/GroupWsRef.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/GroupWsRef.java index 22d8bb9338e..6bf3b834451 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/GroupWsRef.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/GroupWsRef.java @@ -29,7 +29,7 @@ import org.sonar.server.permission.GroupIdOrAnyone; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkState; import static java.util.Objects.requireNonNull; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; /** * Reference to a user group <b>as declared by web service requests</b>. It is one, and only one, diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/GroupWsSupport.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/GroupWsSupport.java index 725c033b37f..4574b958968 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/GroupWsSupport.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/GroupWsSupport.java @@ -36,9 +36,9 @@ import org.sonarqube.ws.UserGroups; import static com.google.common.base.Preconditions.checkArgument; import static java.util.Optional.ofNullable; -import static org.sonar.server.ws.WsUtils.checkFound; -import static org.sonar.server.ws.WsUtils.checkFoundWithOptional; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.NotFoundException.checkFound; +import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; /** * Factorizes code about user groups between web services diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/RemoveUserAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/RemoveUserAction.java index bcca168e355..5e9c6164447 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/RemoveUserAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/RemoveUserAction.java @@ -36,8 +36,8 @@ import static org.sonar.server.usergroups.ws.GroupWsSupport.PARAM_GROUP_NAME; import static org.sonar.server.usergroups.ws.GroupWsSupport.PARAM_LOGIN; import static org.sonar.server.usergroups.ws.GroupWsSupport.defineGroupWsParameters; import static org.sonar.server.usergroups.ws.GroupWsSupport.defineLoginWsParameter; -import static org.sonar.server.ws.WsUtils.checkFound; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.NotFoundException.checkFound; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; public class RemoveUserAction implements UserGroupsWsAction { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/UpdateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/UpdateAction.java index dde339ad21d..eaf6e908910 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/UpdateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/UpdateAction.java @@ -42,8 +42,8 @@ import static org.sonar.server.usergroups.ws.GroupWsSupport.PARAM_GROUP_DESCRIPT import static org.sonar.server.usergroups.ws.GroupWsSupport.PARAM_GROUP_ID; import static org.sonar.server.usergroups.ws.GroupWsSupport.PARAM_GROUP_NAME; import static org.sonar.server.usergroups.ws.GroupWsSupport.toProtobuf; -import static org.sonar.server.ws.WsUtils.checkFound; -import static org.sonar.server.ws.WsUtils.checkFoundWithOptional; +import static org.sonar.server.exceptions.NotFoundException.checkFound; +import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; import static org.sonar.server.ws.WsUtils.writeProtobuf; public class UpdateAction implements UserGroupsWsAction { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usertoken/ws/GenerateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usertoken/ws/GenerateAction.java index 9e405d6696c..932c9f41036 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usertoken/ws/GenerateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usertoken/ws/GenerateAction.java @@ -37,7 +37,7 @@ import static org.sonar.api.utils.DateUtils.formatDateTime; import static org.sonar.server.usertoken.ws.UserTokenSupport.ACTION_GENERATE; import static org.sonar.server.usertoken.ws.UserTokenSupport.PARAM_LOGIN; import static org.sonar.server.usertoken.ws.UserTokenSupport.PARAM_NAME; -import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; import static org.sonar.server.ws.WsUtils.writeProtobuf; public class GenerateAction implements UserTokensWsAction { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usertoken/ws/UserTokenSupport.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usertoken/ws/UserTokenSupport.java index 107cd827607..5873bc4f0cb 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usertoken/ws/UserTokenSupport.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usertoken/ws/UserTokenSupport.java @@ -28,7 +28,7 @@ import org.sonar.server.user.UserSession; import static java.util.Objects.requireNonNull; import static org.sonar.server.user.AbstractUserSession.insufficientPrivilegesException; -import static org.sonar.server.ws.WsUtils.checkFound; +import static org.sonar.server.exceptions.NotFoundException.checkFound; public class UserTokenSupport { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/CreateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/CreateAction.java index 9f485ee9e7d..262cd41c4c8 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/CreateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/CreateAction.java @@ -51,7 +51,7 @@ import static org.sonar.server.ws.KeyExamples.KEY_ORG_EXAMPLE_001; import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; import static org.sonar.server.ws.KeyExamples.NAME_WEBHOOK_EXAMPLE_001; import static org.sonar.server.ws.KeyExamples.URL_WEBHOOK_EXAMPLE_001; -import static org.sonar.server.ws.WsUtils.checkFoundWithOptional; +import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; import static org.sonar.server.ws.WsUtils.checkStateWithOptional; import static org.sonar.server.ws.WsUtils.writeProtobuf; import static org.sonarqube.ws.Webhooks.CreateWsResponse.Webhook; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/DeleteAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/DeleteAction.java index d88edc6149d..33d4efc43ee 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/DeleteAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/DeleteAction.java @@ -35,7 +35,7 @@ import static org.sonar.server.webhook.ws.WebhooksWsParameters.DELETE_ACTION; import static org.sonar.server.webhook.ws.WebhooksWsParameters.KEY_PARAM; import static org.sonar.server.webhook.ws.WebhooksWsParameters.KEY_PARAM_MAXIMUM_LENGTH; import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; -import static org.sonar.server.ws.WsUtils.checkFoundWithOptional; +import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; import static org.sonar.server.ws.WsUtils.checkStateWithOptional; public class DeleteAction implements WebhooksWsAction { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/ListAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/ListAction.java index 5b698ec4101..8c0905c5586 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/ListAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/ListAction.java @@ -47,7 +47,7 @@ import static org.sonar.server.webhook.ws.WebhooksWsParameters.ORGANIZATION_KEY_ import static org.sonar.server.webhook.ws.WebhooksWsParameters.PROJECT_KEY_PARAM; import static org.sonar.server.ws.KeyExamples.KEY_ORG_EXAMPLE_001; import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; -import static org.sonar.server.ws.WsUtils.checkFoundWithOptional; +import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; import static org.sonar.server.ws.WsUtils.checkStateWithOptional; import static org.sonar.server.ws.WsUtils.writeProtobuf; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/UpdateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/UpdateAction.java index 8ca9ac95c35..89fa228a260 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/UpdateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/UpdateAction.java @@ -44,7 +44,7 @@ import static org.sonar.server.webhook.ws.WebhooksWsParameters.URL_PARAM_MAXIMUM import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; import static org.sonar.server.ws.KeyExamples.NAME_WEBHOOK_EXAMPLE_001; import static org.sonar.server.ws.KeyExamples.URL_WEBHOOK_EXAMPLE_001; -import static org.sonar.server.ws.WsUtils.checkFoundWithOptional; +import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; import static org.sonar.server.ws.WsUtils.checkStateWithOptional; public class UpdateAction implements WebhooksWsAction { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/WebhookDeliveryAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/WebhookDeliveryAction.java index 040856eb99f..0e1f9983d13 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/WebhookDeliveryAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/WebhookDeliveryAction.java @@ -35,7 +35,7 @@ import org.sonarqube.ws.Webhooks; import static java.util.Objects.requireNonNull; import static org.sonar.server.webhook.ws.WebhookWsSupport.copyDtoToProtobuf; -import static org.sonar.server.ws.WsUtils.checkFoundWithOptional; +import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; import static org.sonar.server.ws.WsUtils.writeProtobuf; public class WebhookDeliveryAction implements WebhooksWsAction { diff --git a/server/sonar-webserver-ws/src/main/java/org/sonar/server/exceptions/BadRequestException.java b/server/sonar-webserver-ws/src/main/java/org/sonar/server/exceptions/BadRequestException.java index 7a2fdf7166d..3113d202d99 100644 --- a/server/sonar-webserver-ws/src/main/java/org/sonar/server/exceptions/BadRequestException.java +++ b/server/sonar-webserver-ws/src/main/java/org/sonar/server/exceptions/BadRequestException.java @@ -23,6 +23,7 @@ import com.google.common.base.MoreObjects; import java.util.List; import static com.google.common.base.Preconditions.checkArgument; +import static java.lang.String.format; import static java.net.HttpURLConnection.HTTP_BAD_REQUEST; import static java.util.Arrays.asList; @@ -38,6 +39,18 @@ public class BadRequestException extends ServerException { this.errors = errors; } + public static void checkRequest(boolean expression, String message, Object... messageArguments) { + if (!expression) { + throw create(format(message, messageArguments)); + } + } + + public static void checkRequest(boolean expression, List<String> messages) { + if (!expression) { + throw create(messages); + } + } + public static BadRequestException create(List<String> errorMessages) { checkArgument(!errorMessages.isEmpty(), "At least one error message is required"); checkArgument(errorMessages.stream().noneMatch(message -> message == null || message.isEmpty()), "Message cannot be empty"); diff --git a/server/sonar-webserver-ws/src/main/java/org/sonar/server/exceptions/NotFoundException.java b/server/sonar-webserver-ws/src/main/java/org/sonar/server/exceptions/NotFoundException.java index ff5fb2f13c4..f21a98b5157 100644 --- a/server/sonar-webserver-ws/src/main/java/org/sonar/server/exceptions/NotFoundException.java +++ b/server/sonar-webserver-ws/src/main/java/org/sonar/server/exceptions/NotFoundException.java @@ -19,6 +19,10 @@ */ package org.sonar.server.exceptions; +import com.google.common.base.Optional; +import javax.annotation.Nullable; + +import static java.lang.String.format; import static java.net.HttpURLConnection.HTTP_NOT_FOUND; public class NotFoundException extends ServerException { @@ -26,4 +30,36 @@ public class NotFoundException extends ServerException { public NotFoundException(String message) { super(HTTP_NOT_FOUND, message); } + + /** + * @throws NotFoundException if the value if null + * @return the value + */ + public static <T> T checkFound(@Nullable T value, String message, Object... messageArguments) { + if (value == null) { + throw new NotFoundException(format(message, messageArguments)); + } + + return value; + } + + /** + * @throws NotFoundException if the value is not present + * @return the value + */ + public static <T> T checkFoundWithOptional(Optional<T> value, String message, Object... messageArguments) { + if (!value.isPresent()) { + throw new NotFoundException(format(message, messageArguments)); + } + + return value.get(); + } + + public static <T> T checkFoundWithOptional(java.util.Optional<T> value, String message, Object... messageArguments) { + if (!value.isPresent()) { + throw new NotFoundException(format(message, messageArguments)); + } + + return value.get(); + } } diff --git a/server/sonar-webserver-ws/src/main/java/org/sonar/server/ws/WebServiceEngine.java b/server/sonar-webserver-ws/src/main/java/org/sonar/server/ws/WebServiceEngine.java index cbbd7a0389b..4ce8e051e00 100644 --- a/server/sonar-webserver-ws/src/main/java/org/sonar/server/ws/WebServiceEngine.java +++ b/server/sonar-webserver-ws/src/main/java/org/sonar/server/ws/WebServiceEngine.java @@ -50,7 +50,7 @@ import static org.apache.commons.lang.StringUtils.substringAfterLast; import static org.apache.commons.lang.StringUtils.substringBeforeLast; import static org.sonar.server.ws.RequestVerifier.verifyRequest; import static org.sonar.server.ws.ServletRequest.SUPPORTED_MEDIA_TYPES_BY_URL_SUFFIX; -import static org.sonar.server.ws.WsUtils.checkFound; +import static org.sonar.server.exceptions.NotFoundException.checkFound; /** * @since 4.2 diff --git a/server/sonar-webserver-ws/src/main/java/org/sonar/server/ws/WsUtils.java b/server/sonar-webserver-ws/src/main/java/org/sonar/server/ws/WsUtils.java index 2f936764f7d..82ea6a6949d 100644 --- a/server/sonar-webserver-ws/src/main/java/org/sonar/server/ws/WsUtils.java +++ b/server/sonar-webserver-ws/src/main/java/org/sonar/server/ws/WsUtils.java @@ -19,22 +19,14 @@ */ package org.sonar.server.ws; -import com.google.common.base.Optional; -import com.google.common.collect.ImmutableSet; import com.google.protobuf.Message; import java.io.OutputStream; import java.io.OutputStreamWriter; -import java.util.List; -import java.util.Set; -import javax.annotation.Nullable; import org.apache.commons.io.IOUtils; -import org.sonar.api.resources.Qualifiers; import org.sonar.api.server.ws.Request; import org.sonar.api.server.ws.Response; import org.sonar.api.utils.text.JsonWriter; import org.sonar.core.util.ProtobufJsonFormat; -import org.sonar.server.exceptions.BadRequestException; -import org.sonar.server.exceptions.NotFoundException; import static java.lang.String.format; import static java.nio.charset.StandardCharsets.UTF_8; @@ -66,53 +58,6 @@ public class WsUtils { } } - /** - * @throws BadRequestException - */ - public static void checkRequest(boolean expression, String message, Object... messageArguments) { - if (!expression) { - throw BadRequestException.create(format(message, messageArguments)); - } - } - - public static void checkRequest(boolean expression, List<String> messages) { - if (!expression) { - throw BadRequestException.create(messages); - } - } - - /** - * @throws NotFoundException if the value if null - * @return the value - */ - public static <T> T checkFound(@Nullable T value, String message, Object... messageArguments) { - if (value == null) { - throw new NotFoundException(format(message, messageArguments)); - } - - return value; - } - - /** - * @throws NotFoundException if the value is not present - * @return the value - */ - public static <T> T checkFoundWithOptional(Optional<T> value, String message, Object... messageArguments) { - if (!value.isPresent()) { - throw new NotFoundException(format(message, messageArguments)); - } - - return value.get(); - } - - public static <T> T checkFoundWithOptional(java.util.Optional<T> value, String message, Object... messageArguments) { - if (!value.isPresent()) { - throw new NotFoundException(format(message, messageArguments)); - } - - return value.get(); - } - public static <T> T checkStateWithOptional(java.util.Optional<T> value, String message, Object... messageArguments) { if (!value.isPresent()) { throw new IllegalStateException(format(message, messageArguments)); diff --git a/server/sonar-webserver-ws/src/test/java/org/sonar/server/ws/WsUtilsTest.java b/server/sonar-webserver-ws/src/test/java/org/sonar/server/ws/WsUtilsTest.java index 5bbd1a9a891..3a48ff54dca 100644 --- a/server/sonar-webserver-ws/src/test/java/org/sonar/server/ws/WsUtilsTest.java +++ b/server/sonar-webserver-ws/src/test/java/org/sonar/server/ws/WsUtilsTest.java @@ -19,7 +19,6 @@ */ package org.sonar.server.ws; -import java.io.IOException; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -84,7 +83,7 @@ public class WsUtilsTest { @Test public void checkRequest_ok() { - WsUtils.checkRequest(true, "Missing param: %s", "foo"); + BadRequestException.checkRequest(true, "Missing param: %s", "foo"); // do not fail } @@ -93,7 +92,7 @@ public class WsUtilsTest { expectedException.expect(BadRequestException.class); expectedException.expectMessage("Missing param: foo"); - WsUtils.checkRequest(false, "Missing param: %s", "foo"); + BadRequestException.checkRequest(false, "Missing param: %s", "foo"); } } |