Cleanup implementation of REST views

- specify return type if possible
- remove unnecessary throw declarations
- convert some of the thrown exceptions to RestExceptions
- do not throw Exception but specific exceptions
- sort throw declarations (first RestExceptions, then other
  exceptions)

Having explicit return types and exceptions makes it easier to
programatically invoke the REST views, e.g. if a plugin wants to add a
REST view that wraps a Gerrit core REST view.

Change-Id: I5c59553b6cfad457f7ec037cceb08936247bf8e8
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2013-11-11 19:18:54 +01:00
parent bf42bc55b0
commit df134a834a
77 changed files with 287 additions and 266 deletions

View File

@@ -18,9 +18,7 @@ import com.google.common.base.Strings;
import com.google.common.util.concurrent.CheckedFuture;
import com.google.gerrit.common.ChangeHooks;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.BadRequestException;
import com.google.gerrit.extensions.restapi.DefaultInput;
import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.extensions.restapi.RestModifyView;
import com.google.gerrit.extensions.webui.UiAction;
@@ -34,6 +32,7 @@ import com.google.gerrit.server.index.ChangeIndexer;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.util.TimeUtil;
import com.google.gwtorm.server.AtomicUpdate;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
@@ -61,9 +60,8 @@ class PutTopic implements RestModifyView<ChangeResource, Input>,
}
@Override
public Object apply(ChangeResource req, Input input)
throws BadRequestException, AuthException,
ResourceConflictException, Exception {
public Response<String> apply(ChangeResource req, Input input)
throws AuthException, OrmException, IOException {
if (input == null) {
input = new Input();
}
@@ -123,8 +121,8 @@ class PutTopic implements RestModifyView<ChangeResource, Input>,
indexFuture.checkedGet();
}
return Strings.isNullOrEmpty(newTopicName)
? Response.none()
: newTopicName;
? Response.<String>none()
: Response.ok(newTopicName);
}
@Override