Search in sources :

Example 76 with RestApiException

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

the class AccountApiImpl method setName.

@Override
public void setName(String name) throws RestApiException {
    NameInput input = new NameInput();
    input.name = name;
    try {
        putName.apply(account, input);
    } catch (Exception e) {
        throw asRestApiException("Cannot set account name", e);
    }
}
Also used : NameInput(com.google.gerrit.extensions.common.NameInput) DisplayNameInput(com.google.gerrit.extensions.api.accounts.DisplayNameInput) ApiUtil.asRestApiException(com.google.gerrit.server.api.ApiUtil.asRestApiException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException)

Example 77 with RestApiException

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

the class AccountApiImpl method generateHttpPassword.

@Override
public String generateHttpPassword() throws RestApiException {
    HttpPasswordInput input = new HttpPasswordInput();
    input.generate = true;
    try {
        // Response should never be 'none' for a generated password, but
        // let's make sure.
        Response<String> result = putHttpPassword.apply(account, input);
        return result.isNone() ? null : result.value();
    } catch (Exception e) {
        throw asRestApiException("Cannot generate HTTP password", e);
    }
}
Also used : HttpPasswordInput(com.google.gerrit.extensions.common.HttpPasswordInput) IdString(com.google.gerrit.extensions.restapi.IdString) ApiUtil.asRestApiException(com.google.gerrit.server.api.ApiUtil.asRestApiException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException)

Example 78 with RestApiException

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

the class AccountApiImpl method setHttpPassword.

@Override
public String setHttpPassword(String password) throws RestApiException {
    HttpPasswordInput input = new HttpPasswordInput();
    input.generate = false;
    input.httpPassword = password;
    try {
        Response<String> result = putHttpPassword.apply(account, input);
        return result.isNone() ? null : result.value();
    } catch (Exception e) {
        throw asRestApiException("Cannot generate HTTP password", e);
    }
}
Also used : HttpPasswordInput(com.google.gerrit.extensions.common.HttpPasswordInput) IdString(com.google.gerrit.extensions.restapi.IdString) ApiUtil.asRestApiException(com.google.gerrit.server.api.ApiUtil.asRestApiException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException)

Example 79 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 account", 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 80 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 Input());
    } catch (Exception e) {
        throw asRestApiException("Cannot unstar change", e);
    }
}
Also used : AccountResource(com.google.gerrit.server.account.AccountResource) AgreementInput(com.google.gerrit.extensions.api.accounts.AgreementInput) DeleteDraftCommentsInput(com.google.gerrit.extensions.api.accounts.DeleteDraftCommentsInput) NameInput(com.google.gerrit.extensions.common.NameInput) HttpPasswordInput(com.google.gerrit.extensions.common.HttpPasswordInput) StatusInput(com.google.gerrit.extensions.api.accounts.StatusInput) SshKeyInput(com.google.gerrit.extensions.api.accounts.SshKeyInput) Input(com.google.gerrit.extensions.common.Input) DisplayNameInput(com.google.gerrit.extensions.api.accounts.DisplayNameInput) EmailInput(com.google.gerrit.extensions.api.accounts.EmailInput) ChangeResource(com.google.gerrit.server.change.ChangeResource) ApiUtil.asRestApiException(com.google.gerrit.server.api.ApiUtil.asRestApiException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException)

Aggregations

RestApiException (com.google.gerrit.extensions.restapi.RestApiException)93 ApiUtil.asRestApiException (com.google.gerrit.server.api.ApiUtil.asRestApiException)38 IOException (java.io.IOException)31 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)24 UpdateException (com.google.gerrit.server.update.UpdateException)23 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)22 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)20 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)19 AuthException (com.google.gerrit.extensions.restapi.AuthException)18 StorageException (com.google.gerrit.exceptions.StorageException)17 List (java.util.List)17 BatchUpdateOp (com.google.gerrit.server.update.BatchUpdateOp)16 Inject (com.google.inject.Inject)15 ArrayList (java.util.ArrayList)15 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)14 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)14 ChangeContext (com.google.gerrit.server.update.ChangeContext)14 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)14 Provider (com.google.inject.Provider)12 Change (com.google.gerrit.entities.Change)11