]> source.dussan.org Git - sonarqube.git/commitdiff
Rename HttpException to ServerException, and remove ServerErrorException (managed...
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 13 Dec 2013 10:00:46 +0000 (11:00 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 13 Dec 2013 10:00:46 +0000 (11:00 +0100)
12 files changed:
sonar-server/src/main/java/org/sonar/server/exceptions/BadRequestException.java
sonar-server/src/main/java/org/sonar/server/exceptions/ForbiddenException.java
sonar-server/src/main/java/org/sonar/server/exceptions/HttpException.java [deleted file]
sonar-server/src/main/java/org/sonar/server/exceptions/NotFoundException.java
sonar-server/src/main/java/org/sonar/server/exceptions/ServerErrorException.java [deleted file]
sonar-server/src/main/java/org/sonar/server/exceptions/ServerException.java [new file with mode: 0644]
sonar-server/src/main/java/org/sonar/server/exceptions/UnauthorizedException.java
sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionTemplateService.java
sonar-server/src/main/webapp/WEB-INF/app/controllers/application_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/users_controller.rb
sonar-server/src/test/java/org/sonar/server/exceptions/HttpExceptionTest.java [deleted file]
sonar-server/src/test/java/org/sonar/server/exceptions/ServerExceptionTest.java [new file with mode: 0644]

index 6fc45d5e9ae2190b5c9bfb96032a8abc7c4fb26c..669338302fde59cd96a4af6b2ae6900b21bfe71e 100644 (file)
@@ -24,7 +24,7 @@ import javax.annotation.Nullable;
 /**
  * Request is not valid and can not be processed.
  */
-public class BadRequestException extends HttpException {
+public class BadRequestException extends ServerException {
 
   private static final int BAD_REQUEST = 400;
 
index 262cf249395cbbccae15ca471c47d877f819ebae..174367466372a2cd27fa3ce0f4b4145faeda7390 100644 (file)
@@ -22,7 +22,7 @@ package org.sonar.server.exceptions;
 /**
  * Permission denied. User does not have the required permissions.
  */
-public class ForbiddenException extends HttpException {
+public class ForbiddenException extends ServerException {
 
   private static final int FORBIDDEN = 403;
 
diff --git a/sonar-server/src/main/java/org/sonar/server/exceptions/HttpException.java b/sonar-server/src/main/java/org/sonar/server/exceptions/HttpException.java
deleted file mode 100644 (file)
index 7a8cd41..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.exceptions;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
-import java.util.Collection;
-import java.util.Collections;
-
-import static com.google.common.collect.Lists.newArrayList;
-
-public class HttpException extends RuntimeException {
-  private final int httpCode;
-
-  private final String l10nKey;
-  private final Collection<Object> l10nParams;
-
-  public HttpException(int httpCode) {
-    this.httpCode = httpCode;
-    this.l10nKey = null;
-    this.l10nParams = null;
-  }
-
-  public HttpException(int httpCode, String message) {
-    super(message);
-    this.httpCode = httpCode;
-    this.l10nKey = null;
-    this.l10nParams = null;
-  }
-
-  public HttpException(int httpCode, @Nullable String message, @Nullable String l10nKey, @Nullable Object[] l10nParams) {
-    super(message);
-    this.httpCode = httpCode;
-    this.l10nKey = l10nKey;
-    this.l10nParams = l10nParams == null ? Collections.emptyList() : Collections.unmodifiableCollection(newArrayList(l10nParams));
-  }
-
-  public int httpCode() {
-    return httpCode;
-  }
-
-  @CheckForNull
-  public String l10nKey() {
-    return l10nKey;
-  }
-
-  @CheckForNull
-  public Collection<Object> l10nParams() {
-    return l10nParams;
-  }
-}
index d39aa061e5fef9bbe91af5850106eed53277ec79..27a6486e165476a4932f6fafd213a06fa200b3ac 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.server.exceptions;
 
-public class NotFoundException extends HttpException {
+public class NotFoundException extends ServerException {
 
   private static final int NOT_FOUND = 404;
 
diff --git a/sonar-server/src/main/java/org/sonar/server/exceptions/ServerErrorException.java b/sonar-server/src/main/java/org/sonar/server/exceptions/ServerErrorException.java
deleted file mode 100644 (file)
index c5110bf..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-package org.sonar.server.exceptions;
-
-public class ServerErrorException extends HttpException {
-
-  private static final int SERVER_ERROR = 500;
-
-  public ServerErrorException(String message) {
-    super(SERVER_ERROR, message);
-  }
-}
diff --git a/sonar-server/src/main/java/org/sonar/server/exceptions/ServerException.java b/sonar-server/src/main/java/org/sonar/server/exceptions/ServerException.java
new file mode 100644 (file)
index 0000000..8687f7f
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.exceptions;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import static com.google.common.collect.Lists.newArrayList;
+
+public class ServerException extends RuntimeException {
+  private final int httpCode;
+
+  private final String l10nKey;
+  private final Collection<Object> l10nParams;
+
+  public ServerException(int httpCode) {
+    this.httpCode = httpCode;
+    this.l10nKey = null;
+    this.l10nParams = null;
+  }
+
+  public ServerException(int httpCode, String message) {
+    super(message);
+    this.httpCode = httpCode;
+    this.l10nKey = null;
+    this.l10nParams = null;
+  }
+
+  public ServerException(int httpCode, @Nullable String message, @Nullable String l10nKey, @Nullable Object[] l10nParams) {
+    super(message);
+    this.httpCode = httpCode;
+    this.l10nKey = l10nKey;
+    this.l10nParams = l10nParams == null ? Collections.emptyList() : Collections.unmodifiableCollection(newArrayList(l10nParams));
+  }
+
+  public int httpCode() {
+    return httpCode;
+  }
+
+  @CheckForNull
+  public String l10nKey() {
+    return l10nKey;
+  }
+
+  @CheckForNull
+  public Collection<Object> l10nParams() {
+    return l10nParams;
+  }
+}
index 4dd6cedf35bfe876811720175eb72bedd6ff71ac..ba552c49c52cb45ef46f840b9ce6f96a87044959 100644 (file)
@@ -22,7 +22,7 @@ package org.sonar.server.exceptions;
 /**
  * User needs to be authenticated. HTTP request is generally redirected to login form.
  */
-public class UnauthorizedException extends HttpException {
+public class UnauthorizedException extends ServerException {
 
   private static final int UNAUTHORIZED = 401;
 
index 5c6b8ba306960f42de7843048e9642357e290fe1..2b481d4c45c54b523df201ca06852f8571f89e72 100644 (file)
@@ -29,10 +29,10 @@ import org.sonar.core.permission.PermissionTemplateDao;
 import org.sonar.core.permission.PermissionTemplateDto;
 import org.sonar.core.user.UserDao;
 import org.sonar.server.exceptions.BadRequestException;
-import org.sonar.server.exceptions.ServerErrorException;
 
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
+
 import java.util.List;
 import java.util.Map;
 import java.util.regex.Pattern;
@@ -91,11 +91,6 @@ public class InternalPermissionTemplateService implements ServerComponent {
     validateTemplateName(null, name);
     validateKeyPattern(keyPattern);
     PermissionTemplateDto permissionTemplateDto = permissionTemplateDao.createPermissionTemplate(name, description, keyPattern);
-    if (permissionTemplateDto.getId() == null) {
-      String errorMsg = "Template creation failed";
-      LOG.error(errorMsg);
-      throw new ServerErrorException(errorMsg);
-    }
     return PermissionTemplate.create(permissionTemplateDto);
   }
 
index b605def0a17cf94b43f67e8144d77e1a99245475..e07c0b62e000526b0a204353730e8b6f855619bb 100644 (file)
@@ -196,7 +196,7 @@ class ApplicationController < ActionController::Base
       render_native_access_denied(error)
     elsif error.java_kind_of? Java::OrgSonarServerExceptions::ForbiddenException
       render_native_access_denied(error)
-    elsif error.java_kind_of? Java::OrgSonarServerExceptions::HttpException
+    elsif error.java_kind_of? Java::OrgSonarServerExceptions::ServerException
       render_server_exception(error)
     else
       render_error(error)
index 4b1cc9026e60623fd8090d0d1f73d08440065713..3e888a7c35e25ea776bf8fb2e33e7ba07c9a42dc 100644 (file)
@@ -166,7 +166,7 @@ class UsersController < ApplicationController
       Api.users.deactivate(user.login)
       flash[:notice] = 'User is deleted.'
     rescue NativeException => exception
-      if exception.cause.java_kind_of? Java::OrgSonarServerExceptions::HttpException
+      if exception.cause.java_kind_of? Java::OrgSonarServerExceptions::ServerException
         error = exception.cause
         flash[:error] = (error.getMessage ? error.getMessage : Api::Utils.message(error.l10nKey, :params => error.l10nParams.to_a))
       else
diff --git a/sonar-server/src/test/java/org/sonar/server/exceptions/HttpExceptionTest.java b/sonar-server/src/test/java/org/sonar/server/exceptions/HttpExceptionTest.java
deleted file mode 100644 (file)
index 7b6619b..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-package org.sonar.server.exceptions;
-
-import org.junit.Test;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class HttpExceptionTest {
-
-  @Test
-  public void should_create_exception_with_status(){
-    HttpException exception = new HttpException(400);
-    assertThat(exception.httpCode()).isEqualTo(400);
-  }
-
-  @Test
-  public void should_create_exception_with_status_and_message(){
-    HttpException exception = new HttpException(404, "Not found");
-    assertThat(exception.httpCode()).isEqualTo(404);
-    assertThat(exception.getMessage()).isEqualTo("Not found");
-  }
-
-  @Test
-  public void should_create_exception_with_status_and_l10n_message_with_param(){
-    HttpException exception = new HttpException(404, null, "key", new String[]{"value"});
-    assertThat(exception.httpCode()).isEqualTo(404);
-    assertThat(exception.l10nKey()).isEqualTo("key");
-    assertThat(exception.l10nParams()).containsOnly("value");
-  }
-
-  @Test
-  public void should_create_exception_with_status_and_l10n_message_without_param(){
-    HttpException exception = new HttpException(404, null, "key", null);
-    assertThat(exception.httpCode()).isEqualTo(404);
-    assertThat(exception.l10nKey()).isEqualTo("key");
-    assertThat(exception.l10nParams()).isEmpty();
-  }
-}
diff --git a/sonar-server/src/test/java/org/sonar/server/exceptions/ServerExceptionTest.java b/sonar-server/src/test/java/org/sonar/server/exceptions/ServerExceptionTest.java
new file mode 100644 (file)
index 0000000..42acd19
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+package org.sonar.server.exceptions;
+
+import org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class ServerExceptionTest {
+
+  @Test
+  public void should_create_exception_with_status(){
+    ServerException exception = new ServerException(400);
+    assertThat(exception.httpCode()).isEqualTo(400);
+  }
+
+  @Test
+  public void should_create_exception_with_status_and_message(){
+    ServerException exception = new ServerException(404, "Not found");
+    assertThat(exception.httpCode()).isEqualTo(404);
+    assertThat(exception.getMessage()).isEqualTo("Not found");
+  }
+
+  @Test
+  public void should_create_exception_with_status_and_l10n_message_with_param(){
+    ServerException exception = new ServerException(404, null, "key", new String[]{"value"});
+    assertThat(exception.httpCode()).isEqualTo(404);
+    assertThat(exception.l10nKey()).isEqualTo("key");
+    assertThat(exception.l10nParams()).containsOnly("value");
+  }
+
+  @Test
+  public void should_create_exception_with_status_and_l10n_message_without_param(){
+    ServerException exception = new ServerException(404, null, "key", null);
+    assertThat(exception.httpCode()).isEqualTo(404);
+    assertThat(exception.l10nKey()).isEqualTo("key");
+    assertThat(exception.l10nParams()).isEmpty();
+  }
+}