Search in sources :

Example 16 with RestApiException

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

the class ProjectApiImpl method children.

@Override
public List<ProjectInfo> children(boolean recursive) throws RestApiException {
    ListChildProjects list = children.list();
    list.setRecursive(recursive);
    try {
        return list.apply(checkExists());
    } catch (Exception e) {
        throw asRestApiException("Cannot list children", e);
    }
}
Also used : ListChildProjects(com.google.gerrit.server.project.ListChildProjects) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) ApiUtil.asRestApiException(com.google.gerrit.server.api.ApiUtil.asRestApiException) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException)

Example 17 with RestApiException

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

the class SetAccountCommand method setAccount.

private void setAccount() throws OrmException, IOException, UnloggedFailure, ConfigInvalidException, PermissionBackendException {
    user = genericUserFactory.create(id);
    rsrc = new AccountResource(user);
    try {
        for (String email : addEmails) {
            addEmail(email);
        }
        for (String email : deleteEmails) {
            deleteEmail(email);
        }
        if (preferredEmail != null) {
            putPreferred(preferredEmail);
        }
        if (fullName != null) {
            PutName.Input in = new PutName.Input();
            in.name = fullName;
            putName.apply(rsrc, in);
        }
        if (httpPassword != null || clearHttpPassword) {
            PutHttpPassword.Input in = new PutHttpPassword.Input();
            in.httpPassword = httpPassword;
            putHttpPassword.apply(rsrc, in);
        }
        if (active) {
            putActive.apply(rsrc, null);
        } else if (inactive) {
            try {
                deleteActive.apply(rsrc, null);
            } catch (ResourceNotFoundException e) {
            // user is already inactive
            }
        }
        addSshKeys = readSshKey(addSshKeys);
        if (!addSshKeys.isEmpty()) {
            addSshKeys(addSshKeys);
        }
        deleteSshKeys = readSshKey(deleteSshKeys);
        if (!deleteSshKeys.isEmpty()) {
            deleteSshKeys(deleteSshKeys);
        }
    } catch (RestApiException e) {
        throw die(e.getMessage());
    }
}
Also used : AccountResource(com.google.gerrit.server.account.AccountResource) EmailInput(com.google.gerrit.extensions.api.accounts.EmailInput) PutHttpPassword(com.google.gerrit.server.account.PutHttpPassword) PutName(com.google.gerrit.server.account.PutName) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException)

Example 18 with RestApiException

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

the class CreateAccountCommand method run.

@Override
protected void run() throws OrmException, IOException, ConfigInvalidException, UnloggedFailure {
    AccountInput input = new AccountInput();
    input.username = username;
    input.email = email;
    input.name = fullName;
    input.sshKey = readSshKey();
    input.httpPassword = httpPassword;
    input.groups = Lists.transform(groups, AccountGroup.Id::toString);
    try {
        createAccountFactory.create(username).apply(TopLevelResource.INSTANCE, input);
    } catch (RestApiException e) {
        throw die(e.getMessage());
    }
}
Also used : AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) AccountInput(com.google.gerrit.extensions.api.accounts.AccountInput)

Example 19 with RestApiException

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

the class CreateProjectCommand method run.

@Override
protected void run() throws Failure {
    try {
        if (!suggestParent) {
            if (projectName == null) {
                throw die("Project name is required.");
            }
            ProjectInput input = new ProjectInput();
            input.name = projectName;
            if (ownerIds != null) {
                input.owners = Lists.transform(ownerIds, AccountGroup.UUID::get);
            }
            if (newParent != null) {
                input.parent = newParent.getProject().getName();
            }
            input.permissionsOnly = permissionsOnly;
            input.description = projectDescription;
            input.submitType = submitType;
            input.useContributorAgreements = contributorAgreements;
            input.useSignedOffBy = signedOffBy;
            input.useContentMerge = contentMerge;
            input.requireChangeId = requireChangeID;
            input.createNewChangeForAllNotInTarget = createNewChangeForAllNotInTarget;
            input.branches = branch;
            input.createEmptyCommit = createEmptyCommit;
            input.maxObjectSizeLimit = maxObjectSizeLimit;
            if (pluginConfigValues != null) {
                input.pluginConfigValues = parsePluginConfigValues(pluginConfigValues);
            }
            gApi.projects().create(input);
        } else {
            for (Project.NameKey parent : suggestParentCandidates.getNameKeys()) {
                stdout.print(parent.get() + '\n');
            }
        }
    } catch (RestApiException err) {
        throw die(err);
    } catch (PermissionBackendException err) {
        throw new Failure(1, "permissions unavailable", err);
    }
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) ProjectInput(com.google.gerrit.extensions.api.projects.ProjectInput) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException)

Example 20 with RestApiException

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

the class RenameGroupCommand method run.

@Override
protected void run() throws Failure {
    try {
        GroupResource rsrc = groups.parse(TopLevelResource.INSTANCE, IdString.fromDecoded(groupName));
        PutName.Input input = new PutName.Input();
        input.name = newGroupName;
        putName.apply(rsrc, input);
    } catch (RestApiException | OrmException | IOException | NoSuchGroupException e) {
        throw die(e);
    }
}
Also used : OrmException(com.google.gwtorm.server.OrmException) PutName(com.google.gerrit.server.group.PutName) IOException(java.io.IOException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) GroupResource(com.google.gerrit.server.group.GroupResource) NoSuchGroupException(com.google.gerrit.common.errors.NoSuchGroupException)

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