Search in sources :

Example 36 with RestApiException

use of com.google.gerrit.extensions.restapi.RestApiException in project gerrit by GerritCodeReview.

the class ConsistencyChecker method deletePatchSets.

private void deletePatchSets(List<DeletePatchSetFromDbOp> ops) {
    try (BatchUpdate bu = newBatchUpdate()) {
        bu.setRepository(repo, rw, oi);
        for (DeletePatchSetFromDbOp op : ops) {
            checkArgument(op.psId.getParentKey().equals(ctl.getId()));
            bu.addOp(ctl.getId(), op);
        }
        bu.addOp(ctl.getId(), new UpdateCurrentPatchSetOp(ops));
        bu.execute();
    } catch (NoPatchSetsWouldRemainException e) {
        for (DeletePatchSetFromDbOp op : ops) {
            op.p.status = Status.FIX_FAILED;
            op.p.outcome = e.getMessage();
        }
    } catch (UpdateException | RestApiException e) {
        String msg = "Error deleting patch set";
        log.warn(msg + " of change " + ops.get(0).psId.getParentKey(), e);
        for (DeletePatchSetFromDbOp op : ops) {
            // Overwrite existing statuses that were set before the transaction was
            // rolled back.
            op.p.status = Status.FIX_FAILED;
            op.p.outcome = msg;
        }
    }
}
Also used : UpdateException(com.google.gerrit.server.update.UpdateException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) BatchUpdate(com.google.gerrit.server.update.BatchUpdate)

Example 37 with RestApiException

use of com.google.gerrit.extensions.restapi.RestApiException in project gerrit by GerritCodeReview.

the class AccountApiImpl method get.

@Override
public com.google.gerrit.extensions.common.AccountInfo get() throws RestApiException {
    AccountLoader accountLoader = accountLoaderFactory.create(true);
    try {
        AccountInfo ai = accountLoader.get(account.getUser().getAccountId());
        accountLoader.fill();
        return ai;
    } catch (Exception e) {
        throw asRestApiException("Cannot parse change", e);
    }
}
Also used : AccountLoader(com.google.gerrit.server.account.AccountLoader) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) ApiUtil.asRestApiException(com.google.gerrit.server.api.ApiUtil.asRestApiException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException)

Example 38 with RestApiException

use of com.google.gerrit.extensions.restapi.RestApiException in project gerrit by GerritCodeReview.

the class AccountApiImpl method unstarChange.

@Override
public void unstarChange(String changeId) throws RestApiException {
    try {
        ChangeResource rsrc = changes.parse(TopLevelResource.INSTANCE, IdString.fromUrl(changeId));
        AccountResource.StarredChange starredChange = new AccountResource.StarredChange(account.getUser(), rsrc);
        starredChangesDelete.apply(starredChange, new StarredChanges.EmptyInput());
    } catch (Exception e) {
        throw asRestApiException("Cannot unstar change", e);
    }
}
Also used : AccountResource(com.google.gerrit.server.account.AccountResource) ChangeResource(com.google.gerrit.server.change.ChangeResource) StarredChanges(com.google.gerrit.server.account.StarredChanges) ApiUtil.asRestApiException(com.google.gerrit.server.api.ApiUtil.asRestApiException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException)

Example 39 with RestApiException

use of com.google.gerrit.extensions.restapi.RestApiException in project gerrit by GerritCodeReview.

the class AccountApiImpl method starChange.

@Override
public void starChange(String changeId) throws RestApiException {
    try {
        ChangeResource rsrc = changes.parse(TopLevelResource.INSTANCE, IdString.fromUrl(changeId));
        starredChangesCreate.setChange(rsrc);
        starredChangesCreate.apply(account, new StarredChanges.EmptyInput());
    } catch (Exception e) {
        throw asRestApiException("Cannot star change", e);
    }
}
Also used : ChangeResource(com.google.gerrit.server.change.ChangeResource) StarredChanges(com.google.gerrit.server.account.StarredChanges) ApiUtil.asRestApiException(com.google.gerrit.server.api.ApiUtil.asRestApiException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException)

Example 40 with RestApiException

use of com.google.gerrit.extensions.restapi.RestApiException in project gerrit by GerritCodeReview.

the class AccountsImpl method suggestAccounts.

private List<AccountInfo> suggestAccounts(SuggestAccountsRequest r) throws RestApiException {
    try {
        QueryAccounts myQueryAccounts = queryAccountsProvider.get();
        myQueryAccounts.setSuggest(true);
        myQueryAccounts.setQuery(r.getQuery());
        myQueryAccounts.setLimit(r.getLimit());
        return myQueryAccounts.apply(TopLevelResource.INSTANCE);
    } catch (Exception e) {
        throw asRestApiException("Cannot retrieve suggested accounts", e);
    }
}
Also used : QueryAccounts(com.google.gerrit.server.account.QueryAccounts) ApiUtil.asRestApiException(com.google.gerrit.server.api.ApiUtil.asRestApiException) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) AuthException(com.google.gerrit.extensions.restapi.AuthException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException)

Aggregations

RestApiException (com.google.gerrit.extensions.restapi.RestApiException)50 ApiUtil.asRestApiException (com.google.gerrit.server.api.ApiUtil.asRestApiException)16 OrmException (com.google.gwtorm.server.OrmException)14 IOException (java.io.IOException)14 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)12 UpdateException (com.google.gerrit.server.update.UpdateException)12 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)10 Change (com.google.gerrit.reviewdb.client.Change)8 AuthException (com.google.gerrit.extensions.restapi.AuthException)7 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)7 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)7 BatchUpdateOp (com.google.gerrit.server.update.BatchUpdateOp)6 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)5 ArrayList (java.util.ArrayList)5 RevWalk (org.eclipse.jgit.revwalk.RevWalk)5 Test (org.junit.Test)5 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)4 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)4 ChangeContext (com.google.gerrit.server.update.ChangeContext)4 Provider (com.google.inject.Provider)4